74hc164驱动数码管c语言程序,74hc164驱动数码管程序

#define uint unsigned int本文引用地址:http://www.eepw.com.cn/article/201611/317066.htm

#define uchar unsigned char

sbit DAT=P1^1; //模拟串口数据发送端

sbit CLK=P1^2;//模拟时钟控制端

uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff};//0-9,-,全灭 (共阳字段表)

void sendbyte(uchar byte)

{

uchar num,c;

num=tab[byte];

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

{

CLK=0;

DAT=num&0x80; //(0x80即十进制的128, 二进制的10000000 按位发送)

CLK=1;

num<<=1;

}

}

void delay_50ms(unsigned int t) //50MS演示程序

{

unsigned int j;

for(;t>0;t--)

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

{;}

}

main()

{

unsigned char h;

while(1){

for(h=0;h<10;h++){

delay_50ms(1);

sendbyte(h);

delay_50ms(10);

}

h=0;

}

}

下面这段是74ls164 驱动共阴数码管的程序源码

#i nclude

#define uint unsigned int

#define uchar unsigned char

sbit DAT=P1^1;

sbit CLK=P1^2;

uchar code tab[]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xff,0xf6};//0-9,-,全灭

void sendbyte(uchar byte)

{

uchar num,c;

num=tab[byte];

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

{

CLK=0;

DAT=num&0x01;

CLK=1;

num>>=1;

}

}

void delay_50ms(unsigned int t)

{

unsigned int j;

for(;t>0;t--)

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

{;}

}

main()

{

unsigned char h;

while(1){

for(h=0;h<10;h++){

delay_50ms(1);

sendbyte(h);

delay_50ms(10);

}

h=0;

}

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一份基于STM32驱动74HC164驱动四位数码管C语言程序,供您参考: ```c #include "stm32f10x.h" #define CLK_PIN GPIO_Pin_0 #define CLK_PORT GPIOB #define DATA_PIN GPIO_Pin_1 #define DATA_PORT GPIOB void HC164_WriteByte(uint8_t data) { uint8_t i; for(i=0;i<8;i++) { GPIO_ResetBits(CLK_PORT, CLK_PIN); if(data&0x80) GPIO_SetBits(DATA_PORT, DATA_PIN); else GPIO_ResetBits(DATA_PORT, DATA_PIN); data <<= 1; GPIO_SetBits(CLK_PORT, CLK_PIN); } } void Display_Digit(uint8_t digit, uint8_t data) { switch(digit) { case 0: HC164_WriteByte(0x3f); break; case 1: HC164_WriteByte(0x06); break; case 2: HC164_WriteByte(0x5b); break; case 3: HC164_WriteByte(0x4f); break; case 4: HC164_WriteByte(0x66); break; case 5: HC164_WriteByte(0x6d); break; case 6: HC164_WriteByte(0x7d); break; case 7: HC164_WriteByte(0x07); break; case 8: HC164_WriteByte(0x7f); break; case 9: HC164_WriteByte(0x6f); break; default: HC164_WriteByte(0x00); break; } HC164_WriteByte(data); } int main(void) { uint8_t data[4] = {0x01, 0x02, 0x04, 0x08}; uint8_t i, j; GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = CLK_PIN | DATA_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); while(1) { for(i=0;i<4;i++) { for(j=0;j<4;j++) { Display_Digit(j, data[j]); } data[i] <<= 1; if(data[i] == 0) data[i] = 1; delay_ms(1); } } } ``` 其中,`HC164_WriteByte()`函数用于写入一个字节的数据到74HC164芯片;`Display_Digit()`函数用于显示一个数字到数码管上;`main()`函数中的循环用于不断地在四位数码管上显示数字。请注意,该程序中的`delay_ms()`函数需要根据实际情况进行实现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值