Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Keil uart problem with 8051

Status
Not open for further replies.

Keklja

Junior Member level 2
Joined
Nov 11, 2011
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,450
This is my code in Keil:
#include <reg51.h>
#include "stdio.h"
#include "serijska.h"

#define LED P1

#sbit led1=key^0;
#sbit led2=key^1;
#sbit led3=key^2;
#sbit led4=key^3;


char slovo = 0;

unsigned char poruka[40];

int temp = 0;


void main(void){

P1=0x00;



serial_init();


while(1){
if(RI == 1){ //check interupt flag
slovo = serial_getc(); //store primljeni byte

if(slovo == '+'){

sprintf(poruka, "Temp is %d°\r\r", ++temp);

}
else if (slovo == '-') {
sprintf(poruka, "Temp is %d°\r\r", --temp);
}

else if (slovo==0x2F){
sprintf(poruka, "Temp is %d \r\r", temp);
}
else if (slovo=='1'){
led1=1;
serial_send("LED is ON and Blue\r\r");
}
else if (slovo=='2'){
led2=1;
serial_send("LED is ON and Yellow\r\r");
}
else if (slovo=='3'){
led3=1;
serial_send("LED is ON and Green\r\r");
}
else if (slovo=='4'){
led4=1;
serial_send("LED is ON and Red\r\r");
}

serial_send(poruka);


RI = 0;

}




}
}

when i run its working ok when I switch temperature with + and - but if I turn led the message will show that the led is on but after that I get massage witch temperature it is and I should not have that massage. That is my problem. Is it code problem or what? Please help
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top