51 MCU C programming (fifteen 74HC595 control four-digit digital tube)

Publisher:TranquilSilenceLatest update time:2015-09-25 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
[Reprint] 51 MCU C Programming (15 74HC595 Controls Four-digit Digital Tube)


#include
#include

#define uchar unsigned char
#define uint unsigned int

uchar code DAT[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x02,0xf8,0x00,0x10};
sbit SDATA_595=P1^0;   //Serial data input
sbit SCLK_595=P1^1;    //Shift clock pulse
sbit RCK_595=P1^2;     //Output latch control pulse

sbit P20=P2^0;
sbit P21=P2^1;
sbit P22=P2^2;
sbit P23=P2^3;
sbit P24=P2^4;
sbit P25=P2^5;
sbit P26=P2^6;
sbit P27=P2^7;
sbit P30=P3^0;
sbit P31=P3^1;

uchar temp;

void delay(int ms) 
{
 int k;
 while(ms--)
 {
  for(k=0;k<250;k++)
  {
   _nop_();
   _nop_();
  
  }
 }
}

void WR_595(void)       //Send the displayed data to the internal shift register of 74HC595
{
 uchar j;
   for(j=0;j<8;j++)
   {
     temp=temp<<1;
     SDATA_595=CY;
     SCLK_595=1;
    _nop_();
  _nop_();
  SCLK_595=0;
   }
}

void OUT_595(void)      //Store the data in the shift register to the output register and display it
{
   RCK_595=0;
   _nop_();
   _nop_();
   RCK_595=1;   //Send the data to the output latch on the rising edge_nop_
   ();
   _nop_();
   _nop_();
   RCK_595=0;
}

void key_scan()
{
 if(P20==0)
 { while
  (P20==0) ; temp=DAT
  [1]; WR_595();
  OUT_595 ();
  }
 if
 ( P21==0)
 { while(P21==0); temp = DAT [ 2 ]; WR_595 (); OUT_595 (); } if ( WR_59 5 ( ) ; OUT_595(); } if(P25==0) { while(P25==0); temp=DAT[6]; WR_595(); OUT_595(); } if(P26==0) { while(P26==0); temp=DAT[7]; WR_595(); OUT_595(); } if(P27==0) { while(P27==0); temp=DAT[8]; WR_595(); OUT_595(); } if(P30==0) { while(P30==0); temp=DAT[9]; WR_595(); OUT_595(); } if(P31==0) { while(P31==0); temp=DAT[0]; WR_595(); OUT_595(); } } void main() { SCLK_595=0; RCK_595=1; while(1) { key_scan(); //uchar i; //for(i=0;i<10;i++) //{ //   temp=DAT[i];  //Get display data //  WR_595(); //  OUT_595(); //  delay(200); //} } }
  
  
  
  
 
 
 
  
  
  
  
 
 
 
  
  
  
  
 
 
 
  
  
  
  
 
 
 
  
  
  
  
 
 
 
  
  
  
  
 
 
 
  
  
  
  
 
 
 
  
  
  
  
 
 
 
  
  
  
  
 




 
 
 
 
  
     
     
     
      
  
  
  
     
   
 

Reference address:51 MCU C programming (fifteen 74HC595 control four-digit digital tube)

Previous article:51 MCU C programming (14 digital tubes flying in effect)
Next article:About the use of return statement in 51 single chip microcomputer C programming

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号