标题:
Attiny13A单片机+74ls164驱动两位数码管不显示?
[打印本页]
作者:
shuiquan3
时间:
2024-4-4 12:58
标题:
Attiny13A单片机+74ls164驱动两位数码管不显示?
程序如下:
#include <avr/io.h>
#include <util/delay.h>
#define CLR_BIT(val,bitn) (val &=~(1<<(bitn)))//位置零
#define SET_BIT(val,bitn) (val |= (1<<(bitn))) //位置1
// 数码管显示0-9的编码(共阴数码管)
const uint8_t Tab[10] = {
0b11111100, // 0
0b01100000, // 1
0b11011010, // 2
0b11110010, // 3
0b01100110, // 4
0b10110110, // 5
0b10111110, // 6
0b11100000, // 7
0b11111110, // 8
0b11110110 // 9
};
uint8_t DS_data[2];
void separateData(uint8_t dat)
{
DS_data[0]=dat%10;
DS_data[1]=dat/10%10;
}
void write_164(uint8_t dat)
{
uint8_t i;
for(i=0;i<8;i++)
{
CLR_BIT(PORTB,PB1);
if(dat&0x80)
{
SET_BIT(PORTB,PB0);
}
else
{
CLR_BIT(PORTB,PB0);
}
SET_BIT(PORTB,PB1);
dat<<=1;
}
}
void display(void)
{
SET_BIT(PORTB,PB2);
write_164(Tab[DS_data[0]]);
_delay_ms(1);
CLR_BIT(PORTB,PB2);
SET_BIT(PORTB,PB4);
write_164(Tab[DS_data[1]]);
_delay_ms(1);
CLR_BIT(PORTB,PB4);
}
void init(void)
{
// 设置数据和控制引脚为输出
DDRB |= (1 << PB0) | (1 << PB1)| (1 << PB2)| (1 << PB4);
PORTB |= (1 << PB0) | (1 << PB1)| (1 << PB2)| (1 << PB4);
}
int main()
{
init();
separateData(65);
while(1)
{
display();
}
}
作者:
cy009
时间:
2024-4-8 20:46
1.请确认数码管是不是共阴
2.数码管是否有三极管位驱动
3.请上传电路图
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1