We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I'm having a problem with collecting data from Port1. the variable ValueX has a value of FF, regardless of my input through the IO pins.With here i enclose partial of my code, any help or advice is highly appreciated, thank you!
sbit P1^0 BIT0; //these 8 ports will be input . . . . sbit P1^7 BIT7; signed char ValueX = 0x00; . . void ReadValue(void); void main() { P1 = 0xFF; //port set high to activate as input . . } void ReadValue(void) interrupt 0 using 0 { . . . ValueX = ValueX | BIT0; ValueX = (ValueX <<1) | BIT1; ValueX = (ValueX <<1) | BIT2; ValueX = (ValueX <<1) | BIT3; ValueX = (ValueX <<1) | BIT4; ValueX = (ValueX <<1) | BIT5; ValueX = (ValueX <<1) | BIT6; ValueX = (ValueX <<1) | BIT7; } }
Dear all thanks for the advice. But even after i change ValueX = 0x00; in the ISr, and then change the OR logic to ValueX = P1; the value of ValueX is still FF. This is most of my code which i include here(there might be some extra variables). All it does is that it read teh 8 bit data and send it through the TX pin. Any advice please... thanks
#include <reg52.h> sbit LED = P3^3; sbit EXINT = P3^7; sbit BIT7 = P1^0; sbit BIT6 = P1^1; sbit BIT5 = P1^2; sbit BIT4 = P1^3; sbit BIT3 = P1^4; sbit BIT2 = P1^5; sbit BIT1 = P1^6; sbit BIT0 = P1^7; //char ValueX, ValueY; signed int ValueX=0, ValueY; char mouse_in[3]; unsigned char i; char t25ms, seconds; unsigned char byte_num=0; unsigned char flag = 0; unsigned char byte = 0; void TimeDelay (unsigned int milisec); void main (void) { P1 = 0xFF; P3 = 0xFF; LED = 0; TMOD = 0x21; // set timer 0 mode 1 (16-bit mode) timer 1 8 bit auto reload mode TH1 = 0xFD; // 9600 baud rate TR1 = 1; SCON = 0X50; //mode 1, 8 bit data TH0 = 0x4C; // 46080 * 6 / 11.0592MHz = 25ms TL0 = 0; t25ms = 0; seconds = 0; ET0 = 1; // Enable Timer 0 interrupt ES = 1; IT0 = 0; // External interrupt 0 uses low level triggered EX0 = 1; //external interrupt 0 enabled EA = 1; // Enable overall interrupt while(1) { while(flag == 0); TI = 1; } } void SendPacket() interrupt 4 using 2 { TI = 0; SBUF = ValueX; flag = 0; } void ReadBits (void) interrupt 0 using 0 { ValueX = 0x00; LED = 1; TimeDelay(50); LED = 0; ValueX = P1; /* ValueX = (ValueX | BIT7)<<1; ValueX = (ValueX | BIT6)<<1; ValueX = (ValueX | BIT5)<<1; ValueX = (ValueX | BIT4)<<1; ValueX = (ValueX | BIT3)<<1; ValueX = (ValueX | BIT2)<<1; ValueX = (ValueX | BIT1)<<1; ValueX = (ValueX | BIT0); */ flag = 1; } void TimeDelay (unsigned int milisec) { unsigned int i; for (i = 1; i <= milisec; i++) { TH0 = 0xF8; TL0 = 0xCD; TR0 = 1; while (!TF0); TF0 = 0; TR0 = 0; } }
Possibly this is your problem:
void ReadBits (void) interrupt 0 using 0
void ReadBits (void) interrupt 0 using 1
Refer to http://www.keil.com/support/docs/490.htm. Look near the bottom of that page. Jon
thanks for the tips. But the condition doesn't change when i change the using 0 to using 1. I still get FF. I think i found the problem. But i can't seems to fix it. Because when i try to send something to SBUF when i activate the external interrupt ISR, the output would be FF no matter what. But when i disable the external interrupt. i could send what ever data i want. for example, when the external interrupt is activated. when i write SBUF = 0x12; it will just show FF. But when i disable the external interrupt. it'll show the correct value(12). why is this so? Any advice is appreciated? Thanks i advance