数码管根本特点:
1.选用2片595驱动数码管,需求单片机3路IO口,依据数码管动态扫描原理进行显现;
2.宽作业电压3.3V到5V;
3.PCB板尺度:71mm*22mm
4.数码管类型:0.36 4位共阳
商家给的根本材料:最新八位串行595数码管材料.rar
8位数码管的衔接原理图
#include #include// 函数原形界说#define uchar unsigned char#define uint unsigned int void main (void); // 主函数void LED_OUT (uchar X); // LED单字节串行移位函数void LED_print (uchar p, uchar x) ;unsigned char code LED_0F[]; // LED字模表sbit DIO = P1^0; //串行数据输入sbit RCLK = P1^1; //时钟脉冲信号——上升沿有用sbit SCLK = P1^2; //打入信号————上升沿有用uchar Buffer[4] = {0}; //从串口接纳的数据void Init(void){TMOD = 0x20; //8 位主动重装计数PCON &= 0x7f;SCON = 0x50;//串行口操控寄存器 SM1=1,SM0=0方法一波特率可变TH1 = 0xFD; //设置波特率 9600TL1 = 0xFD;TR1 = 1; //发动定时器1TI = 0;RI = 0;ES = 1; //开串口中止EA = 1; //开总中止}// 主程序void main (void) {Init();//初始化LED_print (0x80, 0x0F); //显现发动信息while(1){switch(Buffer[0]){case 0x30: LED_print (0x01, 0); break;case 0x31: LED_print (0x01, 1); break;case 0x32: LED_print (0x01, 2); break;case 0x33: LED_print (0x01, 3); break;case 0x34: LED_print (0x01, 4); break;default : LED_print (0x80, 0x0E); break; }}} void Com_Int(void) interrupt 4{EA = 0;if (RI == 1) //当硬件接纳到一个数据时,RI会置位{Buffer[0] = SBUF ; //这儿减去48是因为从电脑中发送过来的数据是ASCII码。// Buffer[0] = SBUF-48 ;RI = 0; }EA = 1;}void LED_print (uchar p, uchar x) {unsigned char code *led_table; // 查表指针uchar i;unsigned long loop;led_table = LED_0F + x;i = *led_table;LED_OUT(i); LED_OUT(p); RCLK = 0;RCLK = 1;for(loop = 0; loop < 230; loop++);}void LED_OUT(uchar X){uchar i;for(i=8;i>=1;i--){if (X&0x80) DIO=1; else DIO=0;X<<=1;SCLK = 0;SCLK = 1;}}unsigned char code LED_0F[] = {//0 1 2 3 4 5 6 7 8 9 A b C d E F -0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E, 0xbf};