Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1007932
  • 博文数量: 159
  • 博客积分: 4079
  • 博客等级: 上校
  • 技术积分: 2373
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-24 13:35
个人简介

诚实守信!

文章分类

全部博文(159)

文章存档

2015年(2)

2014年(18)

2013年(9)

2012年(57)

2011年(31)

2009年(42)

分类: C/C++

2009-08-17 17:04:10

74HC595级联动态显示的C程序
 
/*该程序为两片74HC595级联实现8位7段LED动态显示的驱动测试程序
   在8个7段LED上显示"01234567"*/

#include
#define uchar unsigned char
uchar bdata OutByte;         /*定义待输出字节变量*/
sbit Bit_Out=OutByte^7;         /*定义输出字节的最高位,即输出位*/
sbit     Bout=P2^0;             /*位输出引脚*/
sbit     Sclk=P2^1;             /*位同步脉冲输出*/
sbit    SLclk=P2^2;             /*锁存脉冲输出*/
uchar code Segment[]={
     0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,         /*共阴7段LED段码表*/
     0x7c,0x39,0x5e,0x79,0x71,0x76,0x73,0x3e,0x00};


void OneLed_Out(uchar i,uchar Location)   /*输出点亮一个7段LED显示器*/
{
     uchar j;

     OutByte=Location;             /*先输出位码*/
     for(j=1;j<=8;j++)
     {
         Bout=Bit_Out;
         Sclk=0;Sclk=1;Sclk=0;     /*位同步脉冲输出*/
         OutByte=OutByte<<1;
     }

     OutByte=Segment[i];         /*再输出段码*/
     for(j=1;j<=8;j++)
     {
         Bout=Bit_Out;
         Sclk=0;Sclk=1;Sclk=0;     /*位同步脉冲输出*/
         OutByte=OutByte<<1;
     }

     SLclk=0;SLclk=1;SLclk=0;     /*一个锁存脉冲输出*/
}

void main()
{
     uchar i=0;
     uchar Location=1;                 /*定义位码*/

     while(1)
     {
         OneLed_Out(i,Location);
         i=i+1;
         Location=Location<<1;

         if(i==8)                 /*8次一轮*/
         {
             i=0;
             Location=1;
         }
     }
}
阅读(11044) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~