Sunday, October 10, 2021

AT89C52 and Multiplexed Display in C using Keil

Programming for multiplexed display in C is straight forward. MCS-51 controller just turn on each digit around 5ms. An important parameter is timing delay created by controller. A timer is need to create a precise timing for controller. 

AT89C52 and Multiplexed Display in C using Keil

However we can use a delay time created by instruction in C loop. It’s not more precise but we can predict this timing delay in both simulator or physical hardware.

AT89C52 and Multiplexed Display in C using Keil

 In this typical example, AT89C52 drives a two-digit multiplexed display. The display is common cathode type. P2 drives display’s segments while P3 drives display’s digits.

In C program we use “for loop” to create timing delay by estimation.

#include <REG52.h>
sbit en1=P3^0;
sbit en2=P3^1;
void delay(unsigned int cnt);
void display(unsigned char d1,unsigned char d2);
// common anode
//unsigned char SSD[16]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
//common cathode
unsigned char SSD[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
unsigned char cnt=0;
void main(){
P2=0x00;
P3=0x00;
while(1) display(9,10);
}
void delay(unsigned int time){
int opt;
for(opt=0;opt<time;opt++);
}
void display(unsigned char d1,unsigned char d2){
P2=SSD[d1];
en1=1;
delay(3000);
en1=0;
P2=SSD[d2];
en2=1;
delay(3000);
en2=0;
}

Click here to download this example program package.


No comments:

Post a Comment

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (54) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (46) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (66) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (2) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (30) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)