The 2051 has:
2 parallel ports - port 1 and port 3
2 timers - timer 0 and timer 1
1 serial port.
(Output pins are shared between uses,
not all of the I/O capability will be available).
The timers can be used as timers or counters.
(use either the system clock, or an external pulse).
Timer 1 can be used as the bit rate clock for the serial port.
The timers have several modes – we will look at
16 bit up counter - each cycle will cause the 16 bit pair TH0/TL0 to increment. When the count gets to 0ffffh it wraps to 0000h and sets an overflow flag.
8 bit up counter with automatic reload.
TL0 counts up.
When the count gets to 0ffh it sets an overflow flag and reloads TL0 with the value in TH0.
This mode is used for the serial bit rate.
The TMOD register controls the mode setting for the two timers:
0 0 M1 M0 0 0 M1 M0
timer 1 timer 0
The TCON register controls the running of the two timers:
TF1 TR1 TF0 TR0 X X X X
TF1 indicates an overflow has occurred
TR1 starts the counter running
The system clock runs at typically 11.0592 Mhz
1 cycle is 1/12 of the clock.
The serial clock runs at 32 times the bit rate.
At 9600 bps we auto reload after each count of 3. -> TH1 has the value 0fdh
Has 4 modes - look only at mode 1 (8bit UART).
SBUF is really two registers. One for input and one for output. Serial I/O works in full-duplex, so the two registers will have different values.
Serial I/O is controlled by the SCON register
SM0 SM1 0 1 0 0 TI RI
SM0 SM1 should be 0 1 for 8 bit UART
The TI bit indicates that the previous output character has been transmitted. It should be cleared by software.
The RI bit indicates that a character has been received. It should be cleared by software.
In the simulator (if the timer and serial i/o systems have been configured) - the serial output is displayed at the bottom of the screen. Keys typed on the keyboard appear as received characters in SBUF
Parallel ports are for general I/O. They are all bi-directional - but if we want to input data we must ensure that we write 1’s to the pins. (they are not full-duplex!)
The simulator is configured so that the parallel ports drive an LCD display.
P1 holds the character to be displayed.
P3.5 acts as a strobe signal. The LCD display will read the value from P1 when P3.5 changes from a 1 to a 0.
The real LCD is a little more complicated.
It must first be intialised.
After sending a character, either the CPU must delay for a small time before sending another, or must wait for a signal from the LCD.
The LCD display also has a command mode (clearing the screen, moving the cursor etc) and a data mode (ASCII characters).
Assembler 9 -