51单片机数码管滚动显示学号_单片机数码管如何显示 101229

bdf2cc9a6a873f8d9bdb867885c67b6f.gif

005beaf5c838c0673d61282305409d15.png

#include

typedef signed char int8;         //8位有符号字符型

typedef signed int int16;         //16位有符号整型

typedef signed long int32;        //32位有符号长整型

typedef unsigned char uint8;      //8位无符号字符型

typedef unsigned int uint16;      //16位无符号整型

typedef unsigned long uint32;     //32位无符号长整型

sbit Segment_election  = P2^5;  //段选74HC573

sbit position_election = P2^6;    //位选74HC573

sbit DATA_A_595      = P1^0;  //74HC595 串行数据输入引脚

sbit SHIFT_CLOCK_595 = P1^4;  //74HC595 移位寄存器时钟信号输入引脚

sbit LATCH_CLOCK_595 = P2^3;  //74HC595 锁存器时钟信号输入引脚

void delay(uint16 x_ms); //延迟  x_ms*1  毫秒

void write_byte_74hc595(uint8 dat);  //给595芯片写一字节数据函数

uint8 character;

uint8 code zifu[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};  //共阳数码管编码表

void main()

   {

P1=0XFF;

write_byte_74hc595(0X40);  //给595芯片写一字节数据函数

write_byte_74hc595(0X00);  //给595芯片写一字节数据函数  关掉595被控制的所有功能

//uint8 zifu[19]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x89,0x7f,0xbf};  //共阳数码管编码表

character=0;

while(1)

    {

       Segment_election=0;

     position_election=0;

     P0=zifu[0];

     Segment_election=1;

     Segment_election=0;

       Segment_election=0;

     position_election=0;

     P0=0X01;

     position_election=1;

     position_election=0;

     delay(3);

   //

Segment_election=0;

     position_election=0;

     P0=zifu[1];

     Segment_election=1;

     Segment_election=0;

       Segment_election=0;

     position_election=0;

     P0= 0x02;

     position_election=1;

     position_election=0;

     delay(3);

//

  Segment_election=0;

     position_election=0;

     P0= (0xbf);

     Segment_election=1;

     Segment_election=0;

       Segment_election=0;

     position_election=0;

     P0=0X04;

     position_election=1;

     position_election=0;

     delay(3);

//

  Segment_election=0;

     position_election=0;

     P0=zifu[1];

     Segment_election=1;

     Segment_election=0;

       Segment_election=0;

     position_election=0;

     P0=0X08;

     position_election=1;

     position_election=0;

     delay(3);

//

  Segment_election=0;

     position_election=0;

     P0=zifu[2];

     Segment_election=1;

     Segment_election=0;

       Segment_election=0;

     position_election=0;

     P0=0X10;

     position_election=1;

     position_election=0;

     delay(3);

//

Segment_election=0;

     position_election=0;

     P0=(0xbf);

     Segment_election=1;

     Segment_election=0;

       Segment_election=0;

     position_election=0;

     P0=0X20;

     position_election=1;

     position_election=0;

     delay(3);

//

  //

Segment_election=0;

     position_election=0;

     P0=zifu [2];

     Segment_election=1;

     Segment_election=0;

       Segment_election=0;

     position_election=0;

     P0=0x40;

     position_election=1;

     position_election=0;

     delay(3);

Segment_election=0;

     position_election=0;

     P0=zifu [9];

     Segment_election=1;

     Segment_election=0;

       Segment_election=0;

     position_election=0;

     P0=0x80;

     position_election=1;

     position_election=0;

     delay(3);

  }

   }

void write_byte_74hc595(uint8 dat)  //给595芯片写一字节数据函数

{

  uint8 i; 

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

{

    DATA_A_595      =(dat<

  SHIFT_CLOCK_595 = 0;  //74HC595 移位寄存器时钟信号输入引脚

  SHIFT_CLOCK_595 = 1;  //74HC595 移位寄存器时钟信号输入引脚

}

 LATCH_CLOCK_595 = 0;  //74HC595 锁存器时钟信号输入引脚

LATCH_CLOCK_595 = 1;  //74HC595 锁存器时钟信号输入引脚

}

void delay(uint16 x_ms) //延迟  x_ms*1  毫秒

{

   uint16 i,j;

for(i=x_ms;i>0;i--)

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

}

0737d7d4136ee3d3e74b9fe00c48b4a4.png

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值