Keklja
Junior Member level 2
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
#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