数码管显示译码器7447与4511各自仅占用PB端口高/低4位引脚,单片机向7447与4511分别写入4位8421BCD码,经2块芯片译码后再向数码管输出数字段码,实现数码管显示。
Proteus运行截图:
Atmel Studio6.2编译通过截图:
程序清单:
/*
* GccApplication23.c
*
* Created: 2014-11-27 20:55:02
* Author: Administrator
*/
#define F_CPU 6000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <stdint.h>
const uint8_t BCD_CODE[] = {1,8,0xFF,4,3,0xFF,2,5,2,0,1,5,0xFF,7,0xFF,6};
int main(void)
{
uint8_t i;
DDRB = 0xFF;PORTB = 0xFF;
DDRC = 0xFF;PORTC = 0xFF;
while(1)
{
//TODO:: Please write your application code
for(i=0;i<8;i++)
{
PORTC = i;
PORTB = BCD_CODE;
_delay_us(500);
}
for(i=8;i<16;i++)
{
PORTC = i;
PORTB = BCD_CODE << 4;
_delay_us(500);
}
}
}
|