hi, i'm using a- 80c31 microcontroller to send the status of port bits: p3.3,p3.4,p3.5 using serial comm. my program works fine only in simulation and i cant get an idea where is the problem. i checked the TX pin(11) with a scope and it seems that no data are being sent.
please help...
#include <Reg51.h> sbit Input1 = 0xB3; /* P3.3 */ sbit Input2 = 0xB4; /* P3.4 */ sbit Input3 = 0xB5; /* P3.5 */ unsigned int Tmr1 = 0; unsigned int Tmr2 = 0; unsigned int Tmr3 = 0; void SendStatus() { if (Input1 == 0){ P2 = P2 | 0x03; Tmr1 = 0; } if (Input2 == 0){ P2 = P2 | 0x18; Tmr2 = 0; } if (Input3 == 0){ P2 = P2 | 0xC0; Tmr3 = 0; } TI = 0; SBUF = P2; while (TI == 0); /* Wait For Transmit */ if (TF0 == 1) { Tmr1 = Tmr1 + 1; Tmr2 = Tmr2 + 1; Tmr3 = Tmr3 + 1; if ((Tmr1>912)&&(Tmr2>912)&&(Tmr3>912)) { Tmr1 = 0; Tmr2 = 0; Tmr3 = 0; TR0 = 0; TF0 = 0; P2 = 0x00; } else if (Tmr1 == 912) {/* 60 Sec Alarm Hold*/ P2 = P2 & 0xFC; } else if (Tmr2 == 912) {/* 60 Sec Alarm Hold*/ P2 = P2 & 0xE7; } else if (Tmr3 == 912) {/* 60 Sec Alarm Hold*/ P2 = P2 & 0x3F; } else { TH0 = 0xFF; TL0 = 0xFF; TF0 = 0; } } } void main() { SCON = 0x40; /* 8-bit UART, BaudRate set by Timer-1 */ TMOD = 0x21; /* Timer1 mode 2, Timer-0 mode 1 */ TCON = 0x40; /* Start baud clock */ TR0 = 0; /* Turn Timer-0 off */ TH0 = 0xFF; TL0 = 0xFF; TF0 = 0; /* Clear rollover flag */ TR0 = 0; /* Turn timer-0 on */ TH1 = 0xCC; /* 600 baud 12MHz */ IE = 0x00; /* Disable serial int */ IP = 0x80; /* Interrupt priority stopped */ P2 = 0x00; P3 = 0x00; Input1 = 1; Input2 = 1; Input3 = 1; while(1) { while ((Input1 == 1)&&(Input2 == 1)&&(Input3 == 1)) { TI = 0; SBUF = 0x00; while (TI == 0);/* Wait For Transmit */ } TH0 = 0xFF; TL0 = 0xFF; TR0 = 1; /* Turn timer-0 on */ while (TR0 == 1) SendStatus(); } }
"i'm confused with unsign char ,char ...."
What, specifically, is the confusion?
Sounds like you need a 'C' textbook?
http://www.keil.com/books/
that is waaaay too 'politically correct'
Erik
i changed my program, and still i found some odd things..
the result are as this
send >expected output> alternate output 1...........0x01..............0x40 2...........0x02..............0x20 3...........0x03..............0xA0 4...........0x04..............0x10 5...........0x05..............0x50 6...........0x06..............0x90 7...........0x07..............0xB0
the alternate output accures when i trigger the input bit again.
#include <Reg51.h> sbit Input1 = 0xB3; /* P3.3 (INT1) bit set, Input 1 */ sbit Input2 = 0xB4; /* P3.4 (T0) bit set, Input 2 */ sbit Input3 = 0xB5; /* P3.5 (T1) bit set, Input 3 */ unsigned char TxOK = 0; unsigned char xt = 0; void serial_IT(void) interrupt 4 { if (TI == 1) { TI = 0; TxOK = 0; } } /* ~~~~~~~~~~ */ /* Main Sub */ /* ~~~~~~~~~~ */ void main(){ SCON = 0x40; TMOD = 0x20; TR0 = 0; TCON = 0x40; TH1 = 0xCC; TL1 = 0x00; ES = 1; EA = 1; TxOK = 1; TI = 1; while(TxOK); while(1){ if (Input1 == 0) { xt = 1; if (Input2 == 0) { xt = 3; if (Input3 == 0) { xt = 6; } } else if (Input3 == 0) { xt = 4; } } else if (Input2 == 0) { xt = 2; if (Input3 == 0) { xt = 5; } } else if (Input3 == 0) { xt = 7; } else xt = 0; TxOK = 1; SBUF = xt; while(TxOK); } }