|
#include <iom64v.h>
#include <macros.h>
#define uint8 unsigned char
#define uint16 unsinged int
/*a为要操作的寄存器, b要操作的位数*/
#define set(a,b) a|(1<<b) //置1
#define clr(a,b) a&~(1<<b) //置0
#define DATA_H set(PORTG,2) //数据输出至74HC164,高电平
#define DATA_L clr(PORTG,2) //数据输出至74HC164,低电平
#define CLK_H set(PORTC,6) //时钟输出至74HC164,高电平
#define CLK_L clr(PORTC,6) //时钟输出至74HC164,低电平
#define CLR_DISABLE set(PORTC,7) //不清除74HC164数据,高电平
#define CLR_ENABLE clr(PORTC,7) //清除74HC164,低电平
#define AA_H set(PORTA,5) //74F138数据高电平
#define AA_L clr(PORTA,5) //74F138数据低电平
#define BB_H set(PORTA,6) //74F138数据高电平
#define BB_L clr(PORTA,6) //74F138数据低电平
#define CC_H set(PORTA,7) //74F138数据高电平
#define CC_L clr(PORTA,7) //74F138数据低电平
uint8 ms2_flag=0;
/* -----------------数码显示扫描缓冲区------------------*/
uint8 uptemp[5]= {0x77,0x12,0xD5,0xD6}; //上排数码管显示数据
uint8 middletemp[4]= {0x77,0x12,0xD5,0xD6}; //中排数码管显示数据
uint8 downtemp[4]= {0x77,0x12,0xD5,0xD6}; //下排数码管显示数据
uint8 Axx[5]={ 0x00 ,0x20 ,0x40 ,0x60};//译码地址
#pragma interrupt_handler timer0:8
void timer0()
{
TCNT0=0x06;
ms2_flag=1;
}
void write_164(uint8 ChrDat)
{
uint8 i;
for(i=8;i>0;i--)
{
if(ChrDat&0x80)// 输出数据
DATA_H;
else
DATA_L;
ChrDat<<=1;//数据移位
CLK_L;
CLK_H;//时钟给上升延信号
}
}
//74F138输入口数据
void write_138(uint8 ChrDat)
{
uint8 i;
i = PORTA & 0x1F ;
ChrDat = ChrDat& 0xE0 ;
PORTA = i | ChrDat;
}
void timer0_init() //2ms iterval
{
TCNT0=0x06;
TCCR0|=(1<<CS01)|(1<<CS00);//1/64
TIMSK|=(1<<OCIE0);
}
void main(void)
{
uint8 temp_address;
PORTA=0x00;
DDRA=0xE0;
PORTC=0x00;
DDRC=0xFC;
PORTG =0x00;
DDRG =0x04;
timer0_init();
SREG|=BIT(7);//使能全局中断
while(1)
{
if(ms2_flag)
{
ms2_flag=0;
temp_address++; //显示位的控制
if (temp_address > 4)
{
temp_address=0 ;
}
write_138(0xC0) ; //不显示
CLR_DISABLE ; //不清除74HC164数据,高电平
write_164(downtemp[temp_address]);
write_164(middletemp[temp_address]);
write_164(uptemp[temp_address]);
write_138(Axx[temp_address ]) ; //显示
}
}
}
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|