📄 iar9-8.c
字号:
#include <iom16.h>
#include<intrinsics.h>
#include "lcd1602_8bit.c"
uchar __flash title1[]={"ICP test"};
uchar __flash title2[]={"ICP1:"};
#define uchar unsigned char
#define uint unsigned int
#define xtal 8
uint value;
uchar flag=0x00;
void port_init(void)
{
DDRA=0xff;
PORTA=0x00;
DDRB=0xff;
PORTB=0x00;
PORTD = 0xff;
DDRD = 0xff;
__no_operation();
DDRD = 0x00;
}
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0x00; //setup
TCNT1L = 0x00;
OCR1AH = 0x1E;
OCR1AL = 0x84;
OCR1BH = 0x1E;
OCR1BL = 0x84;
ICR1H = 0x1E;
ICR1L = 0x84;
TCCR1A = 0x00;
TCCR1B = 0x05; //start Timer
}
/*********************************************/
void init_devices(void)
{
__disable_interrupt(); //disable all interrupts
port_init();
timer1_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x24; //timer interrupt sources
__enable_interrupt();//re-enable interrupts
}
/******************主函数******************/
void main(void)
{
init_devices();
Delay_nms(400);
InitLcd();
ePutstr(4,0,title1);
ePutstr(3,1,title2);
while(1)
{
DisplayOneChar(8,1,(value/10000)+0x30);
DisplayOneChar(9,1,((value%10000)/1000)+0x30);
DisplayOneChar(10,1,((value%1000)/100)+0x30);
DisplayOneChar(11,1,((value%100)/10)+0x30);
DisplayOneChar(12,1,(value%10)+0x30);
}
}
#pragma vector=TIMER1_CAPT_vect
__interrupt void timer1_capt_isr(void)
{
//timer 1 input capture event, read (int)value in ICR1 using;
value=(uint)ICR1L; //Read low byte first (important)
value|=(uint)ICR1H << 8; //Read high byte and shift into top byte
}
#pragma vector=TIMER1_OVF_vect
__interrupt void timer1_ovf_isr(void)
{ __enable_interrupt();
//TIMER1 has overflowed
TCNT1H = 0x00; //reload counter high value
TCNT1L = 0x00; //reload counter low value
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -