8051 C
8051 C
In 8051 C we can access the timer registers TH, TL, and TMOD directly using the reg51.h header file.
See Example 9-20
The same codes put on AT89C51 and DS89C420 will generate different time delay.
The factors of C compiler and MC of others instructions
The C compiler is a factor in the delay size since various 8051 C compilers generate different hex code sizes. So, we still have approximate delay only.
See Examples 9-21
8051 Counters in C
External pulses to T0 (P3.4) and T1 (P3.5). See Examples 9-26 to 9-29.
P1
TL1
LEDs
P3.5
Example 10-15
Write an 8051 C program to transfer the letter A serially at 4800 baud continuously. Use 8-bit data and 1 stop bit. Solution : #include <reg51.h> void main(void) { TMOD=0x20; SCON=0x50; TH1=0xFA; //4800 baud rate TR1=1; while (1) { SBUF=A; while (TI==0); TI=0; } }
Interrupt Programming in C