#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ù)// 全局變量uchar LED[8]; //用于LED的8位顯示緩存void Delay_1ms(uint i)//1ms延時{uchar x,j;for(j=0;jinterrupt 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};
評論