验证中...
开源中国 2018 年度最后一场技术盛会邀你来约~错过就要等明年啦!点此立即预约
gistfile1.txt
原始数据 复制代码
//ICC-AVR application builder : 2010-4-6 下午 10:28:10
// Target : M16
// Crystal: 7.3728Mhz
#include <iom16v.h>
#include <macros.h>
//定义字符表
unsigned char led_7[14]={0xc0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
0x80,0x90,0xff,0x7f,0xc6,0x00};
unsigned char count=0;
unsigned char disp_buff[4]={0,0,0,0};
//根据电路图完善下面的宏定义
#define CLR_SHCLK() PORTB&=~(1<<1) //移位时钟 SCLK
#define SET_SHCLK() PORTB|=(1<<1) //移位时钟 SCLK,上升沿
#define CLR_STCLK() PORTB&=~(1<<0) //锁存时钟 RCLK
#define SET_STCLK() PORTB|=(1<<0) //拉高锁存时钟,上升沿
#define CLR_DS() PORTA&=~(1<<0) //清零
#define SET_DS() PORTA|=(1<<0) //置位
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x01;
PORTB = 0x00;
DDRB = 0x03;
PORTC = 0x00; //m103 output only
DDRC = 0xff;
PORTD |=(1<<3);
DDRD = 0xF0;
}
void Delay_mS(int counter)
{
int i;
while(counter--)
{
for(i=0; i<(187*2); i++)
{}
}
}
//熟悉595驱动函数
/************************************************************
*功 能:74hc595发送字节函数
*说 明:Byte 为要发送的字节
************************************************************/
void HC595_send_byte(unsigned char SndData)
{
//完成595的驱动函数,实现通过595把串行数据发送到Q0——Q7
char i;
for(i=0;i<8;i++)
{
if(SndData&(1<<(7-i)))
{
SET_DS();
}
else
{
CLR_DS();
}
CLR_SHCLK();
SET_SHCLK();
}
CLR_STCLK();
SET_STCLK();
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
int main()
{
unsigned char i;
init_devices();
while(1)
{
/*PORTD=0xE0;
HC595_send_byte(0xA4);
Delay_mS(2);*/
//PORTC = ~(1<<i);
//Delay_mS(500);
for(i=0;i<4;i++)
{//写出实验报告中的功能代码(1)动态扫描(2)按键计数
HC595_send_byte(led_7[disp_buff[i]]);
PORTD &= ~(1<<(7-i));
Delay_mS(2);
PORTD |= 0xf0;
}
if((PIND&(1<<3)) ==0 )
{
Delay_mS(20);
if((PIND&(1<<3)) ==0 )
{
count++;
disp_buff[0] = count/1000;
disp_buff[1] = (count/100)%10;
disp_buff[2] = count/10%10;
disp_buff[3] = count%10;
} while((PIND&(1<<3))==0);
// while((PIND&(1<<3))==0){}
}
}
return 0;
}

评论列表( 0 )

你可以在登录后,发表评论

搜索帮助