值的看一看学习学习
7
打地鼠.zip
488.28 KB
, 阅读权限: 10
, 下载次数: 342
登陆月球.zip
312.98 KB
, 阅读权限: 10
, 下载次数: 630
贩卖机.zip
416.68 KB
, 阅读权限: 10
, 下载次数: 589
扫雷.zip
425.75 KB
, 阅读权限: 10
, 下载次数: 640
象棋.zip
949.51 KB
, 阅读权限: 10
, 下载次数: 591
//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;
}
}
提交评论
谢谢分享!
提交评论
,呵呵,借用一下
提交评论
楼主好人啊,希望大家都像楼主那样啊啊啊
期待楼主下一个佳作
提交评论
111111111111111111111111111噢噢噢噢噢噢噢哦哦哦
提交评论