喜欢的顶一下哦
0
不错,谢谢分享
提交评论
//ICC-AVR application builder : 2013-5-23 23:08:37
// Target : M16
// Crystal: 8.0000Mhz
#include
#include
#include"1602.h"
#include"delay.h"
#define uchar unsigned char
#define uint unsigned int
uint n,f;
void port_init(void)//io口初次化
{
PORTA = 0x00;
DDRA = 0xff;//shuchu
PORTB = 0x00;
DDRB = 0x00;
}
//TIMER0 initialize - prescale:64
// WGM: Normal
// desired value: 1mSec
// actual value: 1.000mSec (0.0%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
TCNT0 = 0x83; //set count
TCCR0 = 0x03; //start timer
}
//TIMER1 initialize - prescale:Rising edge
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 1Hz
// actual value: Out of range
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0x00 /*INVALID SETTING*/; //setup
TCNT1L = 0x00 /*INVALID SETTING*/;
TCCR1B = 0x07; //start Timer打开课本==p 205 表9-10 0000 0111 ok?来1个上升源就加1 懂不?不太懂
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer0_init();
timer1_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x01; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void show (uint temp)
{//12345
LCD_write_string(13,0 ,".hz");
LCD_write_char(8,0,temp/10000);//1
LCD_write_char(9,0,temp/1000%10);//2
LCD_write_char(10,0,temp/100%10); //3
LCD_write_char(11,0,temp/10%10); //4
LCD_write_char(12,0,temp%10); //5
}
void main(void)
{
init_devices();
LCD_init();
while(1)
{
show(f);
}
}
#pragma interrupt_handler timer0_ovf_isr:10
void timer0_ovf_isr(void)
{
TCNT0 = 0x83; //reload counter value//1ms
n++;//ding shi 1s
if(n==1000)//就是要在1s内看他记多少适?就是频率 懂或不懂?知道ok
{
f=TCNT1;//如果有上升源来的话 tcnt1 就会加1 就是计数器来的
TCNT1H = 0x00 /*INVALID SETTING*/; //setup
TCNT1L = 0x00 /*INVALID SETTING*/;
n=0;
}
}
提交评论
啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
提交评论
啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
提交评论
看看这两个程序
提交评论
头像被屏蔽
· 2014-1-2 10:08:57
提交评论