DOC

74hc595

By Jeanette Shaw,2014-06-12 05:45
22 views 0
74hc595

74hc595/74ls595 AVR C程序(一线工人学习进度三)

#include<iom16v.h>

    #include<macros.h>

    unsigned char disp[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};

    #define clr_595_1 PORTB|= (1<<6) #define clr_595_0 PORTB&=~(1<<6) #define clk_595_1 PORTB|= (1<<7) #define clk_595_0 PORTB&=~(1<<7) #define cp_595_1 PORTB|= (1<<4) #define cp_595_0 PORTB&=~(1<<4) #define di_595_1 PORTB|= (1<<5) #define di_595_0 PORTB&=~(1<<5) #define buz_1 PORTD|= (1<<5) #define buz_0 PORTD&=~(1<<5)

unsigned char j,temp;

    void delay_ms(unsigned char a)

     {

     unsigned int i=1000;

     while(a-->0)

     {

     while(i-->0);

     }

     }

    void delay_us(unsigned char a)

     {

     while(a-->0);

     }

void show_595(unsigned char c)/////////595显示

    { int i,x;

     unsigned char num;

     clr_595_1;

     num=disp[c];

    for(i=0;i<8;i++)

     {

     clk_595_0;

     x=num&0x80;

     if(x==0)

     {

     di_595_0;

     }

     else

     {

     di_595_1;

     }

     delay_us(1);

     num=num<<1;

     clk_595_1;

     }

     cp_595_0;

     delay_us(1);

     cp_595_1;

     }

main()

     {

     DDRB=0XFF;

     PORTB=0X00;

     while(1)

     {

     for(j=5;j>0;j--)

     {

     show_595(5-j);/////5-4=1,1开始显示

     PORTB&=~(1<<(j-1));//动态扫描

     delay_us(200);//延时

     PORTB=0X0f;//关扫描位,防重影

     delay_us(200);

     }

     }

    }

此程序功能显示1234,单片机为ATMEGA16,PORTB4位控制4个数码管的开与关

原文地址:http://www.eehome.cn/read.php?tid=2198

Report this document

For any questions or suggestions please email
cust-service@docsford.com