Use of 8-bit digital tube (74hc595 Chip) based on 51 single chip microcomputer

Source: Internet
Author: User
Tags dio prototype definition

#include <at89x51. H> #include <intrins.h>//function prototype definition # UCHAR unsigned char#define uint unsigned int void main (void);//main function void L Ed_out (Uchar X);//LED single byte serial shift function void Led_print (Uchar p, Uchar X); unsigned char code led_0f[];//LED Matrix Sbit DIO = p1^0;          Serial data input Sbit RCLK = p1^1;//clock pulse signal--rising edge effective sbit SCLK = p1^2;//incoming signal ———— rising edge valid Uchar buffer[4] = {0};    Data received from the serial//global variable Uchar led[8];//for the LED 8-bit display cache void delay_1ms (UINT i)//1ms delay {Uchar x,j; for (j=0;j<i;j++) for (x=0;x<=148;x++);    }void Init (void) {tmod = 0x20;//8-bit automatic reload count PCON &= 0x7f; SCON = 0x50;//serial Port control register sm1=1,sm0=0 mode Ipport rate variable TH1 = 0xFD;    Set baud rate 9600 TL1 = 0xFD;    TR1 = 1;    Start Timer 1 TI = 0;    RI = 0;    ES = 1;    Open serial Interrupt EA = 1;        Open Total interrupt}//main program void main (void) {Init ();//Initialize Led_print (0x80, 0x0F);//Display boot information 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)//When the hardware receives a data, the RI will place {buffer[0] = sbuf;//minus 48 here because the data sent from the computer is ASCII code.        Buffer[0] = SBUF-48;     RI = 0; } EA = 1;}          void Led_print (Uchar p, Uchar x) {unsigned char code *led_table; Look up the table pointer 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 <; 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}; 

Based on 51 single-chip microcomputer 8-bit digital tube (74hc595 chip) use method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.