Code C - [expand] 1 2 3 4 5 6 7 8 void ack(){ if (ACKSTAT_bit == 0){ UART1_Write_Text("Ack"); } if (ACKSTAT_bit == 1){ UART1_Write_Text("No Ack"); } }
void ack()
{
if (ACKSTAT_bit == 0) {
UART1_Write_Text("Ack");
}
if (ACKSTAT_bit) {
UART1_Write_Text("No Ack");
}
}
Many users expect this. And from my experience especially those who give vague informations.why would i want someone to write it for me?
I can not detect a clear question...i opened with a question
Don't do this. This just makes threads lengthy ... and might users to keep off responding at all.i guess i wanted to know someone is interested before i got posting
Yes, please do so.so tomorrow after work, i will post details, code, etc.
Search the forum.what are code tags?
void ack(){
if (ACKSTAT_bit) UART1_Write_Text("No Ack");
else UART1_Write_Text("Ack");
}
char Slave = 0x78;
void enter(){
UART1_Write(0x0D);
UART1_Write(0x0A);
}
void ack(){
if (ACKSTAT == 0){
UART1_Write_Text("ACK"); enter();
}
if (ACKSTAT == 1){
UART1_Write_Text("NO ACK"); enter();
}
}
void test(){
char i; UART1_Write_Text("TEST"); enter();
I2C1_Start(); UART1_Write_Text("Start"); enter();
for (i=0;i<255;i++){
I2C1_Wr(i); ack(); UART1_Write_Text(i); enter();
}
I2C1_Stop(); UART1_Write_Text("Stop"); enter();
}
void main() {
GIE_bit = 0; PEIE_bit = 0; RBPU_bit = 0;
TRISA = 0; PORTA = 0; TRISB = 0; PORTB = 0;
TRISC = 0; PORTC = 0; TRISD = 0; PORTD = 0;
TRISE = 0; PORTE = 0; TMR0ON_bit = 0; TMR1ON_bit = 0;
TMR2ON_bit = 0; TMR3ON_bit = 0; CCP1CON = 0;
USBEN_bit = 0; SUSPND_bit = 1; SPPEN_bit = 0;
CLK1EN_bit = 0; CSEN_bit = 0;
SSPEN_bit = 0; SSPEN_bit = 0;
//TXEN_bit = 0; SPEN_bit = 0;
CREN_bit = 0;
ADON_bit = 0; ADCON1 = 0x0F; CMCON = 0x07;
CVREN_bit = 0; CVROE_bit = 0; HLVDEN_bit = 0;
UART1_Init(115200);
Delay_ms(100);
UART1_Write_Text("HELLO");
I2C1_Init(100000);
test();
do{
}while(1);
}
this always writes "ack" to uart. never "no ack".
#define SDA TRISC.B4
#define SCL TRISC.B3
sbit white at PORTE.B0;
sbit red at PORTD.B1;
sbit green at PORTD.B2;
sbit blue at PORTD.B3;
bit oldstate_01;
bit oldstate_02;
bit speed;
bit colors;
bit color_temp;
char const text1[] = ("COG Test 2x20 Module");
char const text2[] = ("TESTING TESTING TEST");
char const text3[] = ("Testing Contrast Set");
char const text4[] = ("Testing Folower Cont");
char const text5[] = {"NEWHAVEN DisplayXXXX"};
char const text6[] = {"2x20 LCD Module XXXX"};
char const text7[] = {"YO YO YO"};
const char Slave = 0x00;
const char Comsend = 0x00;
const char Datasend = 0x40;
const char Line2 = 0xC0;
char old, new, count, time, color;
int i;
void single_digits(unsigned int i){// this write variables out uart from
i = i / 100; // 0 - 255 in readable digits and not
UART1_Write(i + 48); // random garbage
i = i % 100;
i = i / 10;
UART1_Write(i + 48);
i = i % 10;
i = i / 1;
UART1_Write(i + 48);
}
void enter(){ // this is return line feed and carriage
UART1_Write(0X0D); // return for uart so everything gets is
UART1_Write(0X0A); // own line, easier reading
}
void blink(char times_blink){ // blink led for debugging wherever i need
char i; // simple test
for (i=0;i<times_blink;i++){
white = ~white;
Delay_ms(50);
}
white = 0;
}
void rotary(){old = PORTC; new = old & 0b00000011;
if (new == 1){ // rotary encoder function, simple but a
if (speed == 0){ // little buggy, i will clean later after
count++; // I2C is functioning. rotary is used to
Delay_ms(200); // increment the variable "count". holding
} // the button for 2 seconds enables the
if (speed == 1){count = count + 10;} // "speed" variable to move
Delay_ms(100); // through variables by counting by 10
single_digits(count); // instead of by 1.
enter();
}
if (new == 2){
if (speed == 0){
count--;
Delay_ms(200);
}
if (speed == 1){
count = count - 10;
}
Delay_ms(100);
single_digits(count);
enter();
}
}
void min_max(){
char old = 0;
char new = 0;
/*if (count <= 0){count = 0;} // used when i want to set a minimum or
if (count >= 15){count = 15;} // maximum on a variable. not need right
if (count >= 200){count = 0;}*/ // now
if (old != new){ // this outputs uart the new "count"
UART1_Write_Text("count = 0");// variable when it changes to a new
write_count(); // variable
enter();
}
old = new;
}
void InitTimer0(){ // this is for the rotary encoder button,
T0CON = 0x86; // to check for a 2 second press. which
TMR0H = 0x67; // changes the counting of the encoder.
TMR0L = 0x69; // i.e. counts by 1's or 10's
GIE_bit = 1;
TMR0IE_bit = 1;
}
void Interrupt(){
if (SSPIF_bit){ // I2C Interrupt, not implemented yet.
SSPIF_bit = 0;}
if (TMR0IF_bit){ // rotary encoder timer interrrupt
TMR0IF_bit = 0;
TMR0H = 0x67;
TMR0L = 0x69;
//Enter your code here
TMR0ON_bit = 0;
SSPBUF = count;
speed = ~speed;
white = ~white;}
}
void rgb(){ // function to change through colors on
UART1_Write(color + 48); // the LCD. this is the button on
enter();// next(); // PORTE.B1
if (color >= 6){
color = 0;
}
switch(color){
case 0: red = 1; green = 0; blue = 0; UART1_Write_Text("RED"); enter(); break; // next(); break;
case 1: red = 1; green = 1; blue = 0; UART1_Write_Text("ORANGE"); enter(); break; // next(); break;
case 2: red = 0; green = 1; blue = 0; UART1_Write_Text("GREEN"); enter(); break; // next(); break;
case 3: red = 0; green = 1; blue = 1; UART1_Write_Text("CYAN"); enter(); break; // next(); break;
case 4: red = 0; green = 0; blue = 1; UART1_Write_Text("BLUE"); enter(); break; //next(); break;
case 5: red = 1; green = 0; blue = 1; UART1_Write_Text("PURPLE"); enter(); break; //next(); break;
}
}
void color_change(){ // activate for lcd color changing
if (color_temp == 1){ // JUST FOR FUN ONLY
color = count;
if (colors != 0){
color++;
Vdelay_ms(time);
rgb();
}
}
}
/***************************************************/
/****************************************************
DANGER ... I2C ZONE ... DANGER
****************************************************/
/***************************************************/
/****************************************************
* ACK Test *
****************************************************/
void ack(){
if (ACKSTAT_bit == 0){
UART1_Write_Text("Ack");
}
if (ACKSTAT_bit == 1){
UART1_Write_Text("No Ack");
}
}
/***************************************************/
/****************************************************
* Delay Subroutine *
****************************************************/
void delay(unsigned int n){
unsigned int i, j;
[COLOR="#000000"] for (i=0;i<n;i++){[/COLOR]
for (j=0;j<350;j++){
;}
}
}
/***************************************************/
/****************************************************
* Output command or data via I2C *
****************************************************/
void I2C_out(unsigned char j){ //I2C Output
int n;
unsigned char d;
d = j;
enter(); //UART1_Write_Text("Entered I2C_out"); enter();
for(n=0;n<8;n++){ //UART1_Write_Text("Entered for loop"); enter();
if((d & 0x80) == 0x80){ //UART1_Write_Text("entered if statement"); enter();
SDA = 1;//SDA_SET;
//UART1_Write_Text("ii = ");
//UART1_Write(ii); ii++; enter();
//UART1_Write_Text("if - d = ");
//UART1_Write(d); enter();
}
else
SDA = 0;//SDA_CLR;
//UART1_Write_Text("entered else statement"); enter();
//UART1_Write_Text("else - d = ");
//UART1_Write(d); enter();
d = (d << 1);
SCL = 0;//SCL_CLR;
SCL = 1;//SCL_SET;
SCL = 0;//SCL_CLR;
}
SCL = 1;//SCL_SET;
//UART1_Write_Text("7"); enter();
while(SDA == 1/*SDA_SET*/){
SCL = 0;//SCL_CLR;
SCL = 1;//SCL_SET;
//UART1_Write_Text("8"); enter();
}
SCL = 0;//SCL_CLR;
} //UART1_Write_Text("MADE IT THROUGH"); enter();
/***************************************************/
/****************************************************
* I2C Start *
****************************************************/
void I2C_Start(void){
SCL = 1;//SCL_SET;
SDA = 1;//SDA_SET;
SDA = 0;//SDA_CLR;
SCL = 0;//SCL_CLR;
}
/***************************************************/
/****************************************************
* I2C Stop *
****************************************************/
void I2C_Stop(void){
SDA = 0;//SDA_CLR;
SCL = 0;//SCL_CLR;
SCL = 1;//SCL_SET;
SDA = 1;//SDA_SET;
}
/***************************************************/
/****************************************************
* Send string of ASCII data to LCD *
****************************************************/
void Show(unsigned char *text){
int n; //UART1_Write_Text("1"); enter();
I2C_Start(); //UART1_Write_Text("3"); enter();
I2C_out(Slave); //UART1_Write_Text("4"); enter(); //ack(); enter();
I2C_out(Datasend); //UART1_Write_Text("5"); enter(); //ack(); enter();
for(n=0;n<20;n++){
I2C_out(*text); //UART1_Write(ii); ii++; enter(); //ack(); enter();
++text;
}
I2C_Stop();
}
/***************************************************/
/****************************************************
* Next Line *
****************************************************/
void nextline(void){
I2C_Start();
I2C_out(Slave);
I2C_out(Comsend);
I2C_out(line2);
I2C_Stop();
}
/***************************************************/
/****************************************************
* Initialization For ST7036i *
****************************************************/
void init_LCD(){ UART1_Write_Text("INIT LCD"); enter();
I2C_START();
SSPBUF = Slave; UART1_Write_Text("Slave"); enter(); ack(); enter();
SSPBUF = Comsend; UART1_Write_Text("Comsend"); enter(); ack(); enter();
SSPBUF = 0x38; Delay_ms(10); UART1_Write_Text("Function Set"); enter(); ack(); enter();
SSPBUF = 0x39; Delay_ms(10); UART1_Write_Text("Function Set"); enter(); ack(); enter();
SSPBUF = 0x14; UART1_Write_Text("Bias Set"); enter(); ack(); enter();
SSPBUF = 0x78; UART1_Write_Text("Contrast Set"); enter(); ack(); enter();
SSPBUF = 0x5E; UART1_Write_Text("Power/Icon/Contrast Control"); enter(); ack(); enter();
SSPBUF = 0x6D; UART1_Write_Text("Follower Control"); enter(); ack(); enter();
SSPBUF = 0x0F; UART1_Write_Text("Display On/Off"); enter(); ack(); enter();
SSPBUF = 0x01; UART1_Write_Text("Clear Display"); enter(); ack(); enter();
SSPBUF = 0x06; Delay_ms(10); UART1_Write_Text("Entry Mode Set"); enter(); ack(); enter();
I2C_STOP(); UART1_Write_Text("Exit Entry Mode Set"); enter(); ack(); enter();
}
/***************************************************/
/****************************************************
* Clear, Home, Entry Mode and Display On for LCD *
****************************************************/
void clear_home(){ UART1_Write_Text("CLEAR HOME"); enter();
I2C_Start();
I2C_out(Slave); ack(); UART1_Write_Text(" slave"); enter();
I2C_out(Comsend); ack(); UART1_Write_Text(" comsend"); enter();
I2C_out(0x01); ack(); /*/ Clear Display */ UART1_Write_Text("clear display"); enter();
I2C_out(0x02); ack();/*/ Return Home */ UART1_Write_Text(" return home"); enter();
I2C_out(0x06); ack();/*/ Entry Mode Set */ UART1_Write_Text(" entry mode"); enter();
I2C_out(0x0C); ack();/*/ Display On */ UART1_Write_Text(" display on"); enter();
I2C_out(0x30); ack();/*/ Function Set */ UART1_Write_Text(" function set"); enter();
I2C_Stop();
}
/***************************************************/
/****************************************************
* Write *
****************************************************/
void write(){ UART1_Write_Text("WRITE"); enter();
I2C_Start();
I2C_Stop();}
/***************************************************/
/****************************************************
* Contrast *
****************************************************/
void contrast(){
int n;
int i; enter(); UART1_Write_Text("CONTRAST"); enter();
I2C_start();
I2C_out(slave); ack(); Delay_ms(2); UART1_Write_Text("Slave"); enter();
I2C_out(0x40); ack(); Delay_ms(2); UART1_Write_Text("Comsend"); enter();
UART1_Write_Text("for loop 1"); enter();
for (n = 0; n < 20; n++){ UART1_Write(n); enter();
I2C_out(text1[n]);Delay_ms(1);
}
I2C_Stop();
nextline();
I2C_Start();
I2C_out(Slave);
I2C_out(Datasend);
for (n = 0; n < 20; n++){
I2C_out(text3[n]);
}
I2C_Stop();
Delay_ms(200); UART1_Write_Text("for loop 2"); enter();
for (i = 122; i < 128; i++){ UART1_Write(i); enter();
I2C_Start();
I2C_out(Slave); //UART1_Write_Text("Slave"); enter();
I2c_out(Comsend); //UART1_Write_Text("Comsend"); enter();
I2C_out(0x39);
Delay_ms(10);
I2C_out(i);
I2C_Stop();
Delay_ms(300);
} UART1_Write_Text("for loop 3"); enter();
for (i = 94; i < 96; i++){ UART1_Write(i); enter();
I2C_Start();
I2C_out(Slave); //UART1_Write_Text("Slave"); enter();
I2C_out(Comsend); //UART1_Write_Text("Comsend"); enter();
I2C_out(0x39);
Delay_ms(10);
I2C_out(i);
I2C_Stop();
Delay_ms(300);
}
init_LCD(); UART1_Write_Text("Done"); enter();
}
/***************************************************/
/****************************************************
* *
****************************************************/
/***************************************************/
/***************************************************/
/***************************************************/
void main() {
INTCON = 0b11100000; INTCON2.B7 = 1; IPEN_bit = 0; PIE1 = 0b00001000;
TRISA = 0; PORTA = 0; LATA = 0; TRISB = 0; PORTB = 0; LATB = 0;
TRISC = 0b0001111; PORTC = 0; LATC = 0;
TRISD = 0b00000001; PORTD = 0; LATD = 0;
TRISE = 0b00000010; PORTE = 0; LATE = 0;
TMR0ON_bit = 0; TMR1ON_bit = 0; TMR2ON_bit = 0; TMR3ON_bit = 0;
CCP1CON = 0; CCP2CON = 0;
//SSPSTAT = 0;
SSPEN_bit = 1; SSPCON1.B3 = 1; SSPCON1.B2 = 0; SSPCON1.B1 = 0; SSPCON1.B0 = 0;
BRG16_bit = 0; SSPADD = 0x13;
TXEN_bit = 0; SPEN_bit = 0; CREN_bit = 0;
ADON_bit = 0; ADCON1 = 0x0F;
CMCON = 0x07; CVREN_bit = 0; CVROE_bit = 0;
HLVDEN_bit = 0;
Delay_ms(100);
UART1_Init(115200);
Delay_ms(100);
enter();
UART1_Write_Text("hello");
enter();
oldstate_01 = 0; oldstate_02 = 0; speed = 0; color = 3; color_temp = 0;
count = 0; colors = 0; time = 0;
blink(10);
rgb();
init_LCD(); // JUST TRYING TO GET THIS WORKING FIRST
//contrast(); // maybe adjust the contrast a little,
//I2C_out(3); // THEN TRY FOR A SINGLE ASCII TO LCD
do{
min_max();
rotary();
//color_change();
if (Button(&PORTE,1,1,1)){// this button changes colors in RGB function
oldstate_01 = 1;
white = 0;
}
if (oldstate_01 && Button(&PORTE,1,1,0)){
oldstate_01 = 0;
color++;
rgb();
}
if (Button(&PORTD,0,1,1)){// this is rotary encoder button
oldstate_02 = 1;
white = 0;
}
if (oldstate_02 && Button(&PORTD,0,1,0)){
oldstate_02 = 0;
inittimer0();
write_count();
color_temp = ~color_temp;
UART1_Write_Text("speed = ");
UART1_Write(speed); enter();
write_time();
UART1_Write_Text("color_temp = ");
UART1_Write(color_temp); enter(); enter();
}
}while(1);
}
Did you really pay attention on the above reply, or at least spent any time to review the correct code before posting ? Regardless of the naming, both ACKSTAT or ACKSTAT_bit are within in the same ack() function; none appear anywhere else, and you still did't say how it is being declared; as an ordinary boolean variable, or as pinout assignment.
Perhaps and probably obviously, i dont understad.
Anyway, do you understand what is meant by variable declaration ?
void ack(){
if (ACKSTAT_bit == 0){
UART1_Write_Text("Ack");
}
Ok, just to make sure you got the point: Since this routine is always executing the snippet below, we need to know what this variable ACKSTAT_bit is; the mapping of an I/O input, or a user-defined variable:
Code:void ack(){ if (ACKSTAT_bit == 0){ UART1_Write_Text("Ack"); }
So what is the problem at all? It sounds like you ARE reading it. Since you allways get an ACK, shoulnd't you celebrate this ? If you want to force a NO ACK (NACK) in the sake of experimenting, perhaps removing the display device from I2C bus could provide you this case.i really feel like i should be able to read this, since its a register
So what is the problem at all? It sounds like you ARE reading it. Since you allways get an ACK, shoulnd't you celebrate this ? If you want to force a NO ACK (NACK) in the sake of experimenting, perhaps removing the display device from I2C bus could provide you this case.
in an earlier post, i stated that i removed the lcd and got same responses. i was being told i was getting an 'ack', without the lcd.
Prototype
Returns
- unsigned short I2C1_Wr(unsigned short data_);
- Returns 0 if there were no errors.
for (i=0;i<255;i++){
I2C1_Wr(i); ack(); UART1_Write_Text(i); enter();
}
for (i=0;i<255;i++){
if ( I2C1_Wr(i) == 0 );
UART1_Write_Text(i); UART1_Write_Text("Ack"); UART1_Write_Text(i); enter();
else
UART1_Write_Text(i); UART1_Write_Text("No Ack"); UART1_Write_Text(i); enter();
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?