Back to PCAM+ page.
Back to Chapter 4 7-Segment Display Interface with 8051 MicrocontrollersSeven-segment displays are nothing more than well arranged LEDs inside a box — actually eight of them when you count the decimal point. As such, the interfacing code should be as simple as interfacing a row of LEDs. Indeed it is simple, though the complexity is in multiplexing displays.Here, we'll write a program that will display the number 4321 on the seven-segment LED displays of the PCAM+ board. First, make these connections using the jumper wires, but be sure to use the D1 etc. pins on the side of the seven-segment LEDs and not the ones with the same names used previously for the single-row LED examples. - Connect P2.0 from the microcontroller to pin D1 of the seven-segment LEDs
- Connect P2.1 from the microcontroller to pin D2 of the seven-segment LEDs
- Connect P2.2 from the microcontroller to pin D3 of the seven-segment LEDs
- Connect P2.3 from the microcontroller to pin D4 of the seven-segment LEDs
- Likewise, connect P3.0 through P3.7 to pins "a" through "•" on the other side of the seven-segment LEDs
Enter the following code in 8051IDE: MOV P2,#00000000B
MAIN: LCALL SHOW SJMP MAIN
SHOW: MOV P2,#00001000B LCALL ONE LCALL DELAY
MOV P2,#00000100B LCALL TWO LCALL DELAY
MOV P2,#00000010B LCALL THREE LCALL DELAY
MOV P2,#00000001B LCALL FOUR LCALL DELAY RET
ZERO: MOV P3,#0C0H RET
ONE: MOV P3,#0F9H RET
TWO: MOV P3,#0A4H RET
THREE: MOV P3,#0B0H RET
FOUR: MOV P3,#99H RET
FIVE: MOV P3,#092H RET
SIX: MOV P3,#82H RET
SEVEN: MOV P3,#0F8H RET
EIGHT: MOV P3,#80H RET
NINE: MOV P3,#90H RET
DELAY: MOV R5,#1D LOOP1: MOV R6,#25D LOOP2: MOV R7,#100D DELAY_LOOP: DJNZ R7,$ DJNZ R6,LOOP2 DJNZ R5,LOOP1 RET Assemble and download the code to the PCAM+ board as usual. Proceed to Chapter 6
Back to PCAM+ page. |