x is not used, taken as 0.
Project PDL
The operation of the project is shown in Figure 6.26 with a PDL. At the beginning of the program an array called SEGMENT is declared and filled with the relationships between the numbers 0 and 9 and the data to be sent to PORTC. The PORTC pins are then configured as outputs, and a variable is initialized to 0. The program then enters an endless loop where the variable is incremented between 0 and 9 and the corresponding bit pattern to turn ON the appropriate segments is sent to PORTC continuously with a one-second delay between outputs.
START
Create SEGMENT table
Configure PORTC as outputs
Initialize CNT to 0
DO FOREVER
Get bit pattern from SEGMENT corresponding to CNT
Send this bit pattern to PORTC
Increment CNT between 0 and 9
Wait 1 second
ENDDO
END
Figure 6.26: PDL of the project
Project Program
The program is called SEVEN1.C and the listing is given in Figure 6.27. At the beginning of the program character variables Pattern and Cnt are declared, and Cnt is cleared to 0. Then Table 6.8 is implemented using array SEGMENT. After configuring the PORTC pins as outputs, the program enters an endless loop using a for statement. Inside the loop the bit pattern corresponding to the contents of Cnt is found and stored in variable Pattern. Because we are using a common anode display, a segment is turned ON when it is at logic 0 and thus the bit pattern is inverted before it is sent to PORTC. The value of Cnt is then incremented between 0 and 9, after which the program waits for a second before repeating the above sequence.
/*****************************************************************************
7-SEGMENT DISPLAY
=================
In this project a common anode 7-segment LED display is connected to PORTC
of a PIC18F452 microcontroller and the microcontroller is operated from a 4MHz
resonator. The program displays numbers 0 to 9 on the display with a one
second delay between each output.
Author: Dogan Ibrahim
Date: July 2007
File: SEVEN1.C
******************************************************************************/
void main() {
unsigned char Pattern, Cnt = 0;
unsigned char SEGMENT[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,