#51單片機#8位數(shù)碼管(74HC595芯片)的使用方法
1.采用2片595驅(qū)動數(shù)碼管,需要單片機3路IO口,根據(jù)數(shù)碼管動態(tài)掃描原理進行顯示;
2.寬工作電壓3.3V到5V;
3.PCB板尺寸:71mm*22mm
4.數(shù)碼管型號:0.36 4位共陽
商家給的基本資料:最新八位串行595數(shù)碼管資料.rar
8位數(shù)碼管的連接原理圖
#include #include// 函數(shù)原形定義#define uchar unsigned char#define uint unsigned int void main (void); // 主函數(shù)void LED_OUT (uchar X); // LED單字節(jié)串行移位函數(shù)void LED_print (uchar p, uchar x) ;unsigned char code LED_0F[]; // LED字模表sbit DIO = P1^0; //串行數(shù)據(jù)輸入sbit RCLK = P1^1; //時鐘脈沖信號——上升沿有效sbit SCLK = P1^2; //打入信號————上升沿有效uchar Buffer[4] = {0}; //從串口接收的數(shù)據(jù)void Init(void){TMOD = 0x20; //8 位自動重裝計數(shù)PCON &= 0x7f;SCON = 0x50;//串行口控制寄存器 SM1=1,SM0=0方式一波特率可變TH1 = 0xFD; //設(shè)置波特率 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) //當(dāng)硬件接收到一個數(shù)據(jù)時,RI會置位{Buffer[0] = SBUF ; //這里減去48是因為從電腦中發(fā)送過來的數(shù)據(jù)是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};
評論