📄 cycleforsmall100us.c
字号:
//ICC-AVR application builder : 2005-6-30 12:09:57
// Target : M16
// Crystal: 7.3728Mhz
#include <iom16v.h>
#include "D:\ICC_H\CmmICC.H"
/* control port */
#define SET_RS PORTA |= 0x01
#define CLR_RS PORTA &= 0xFE
#define SET_RW PORTA |= 0x02
#define CLR_RW PORTA &= 0xFD
#define SET_E PORTA |= 0x04
#define CLR_E PORTA &= 0xFB
/* data port */
#define SET_D4 PORTA |= 0x10 //SET PA4
#define CLR_D4 PORTA &= 0xEF //CLR PA4
#define SET_D5 PORTA |= 0x20 //SET PA5
#define CLR_D5 PORTA &= 0xDF //CLR PA5
#define SET_D6 PORTA |= 0x40 //SET PA6
#define CLR_D6 PORTA &= 0xBF //CLR PA6
#define SET_D7 PORTA |= 0x80 //SET PA7
#define CLR_D7 PORTA &= 0x7F //CLR PA7
/* busy port */
#define GET_BF PINA & 0x80 //GET PD7
#define OUTPUT_BF DDRA |= 0x80 //OUTPUT
#define INPUT_BF DDRA &= 0x7F //INPUT
#include "D:\ICC_H\LCD1602_.H"
uint32 cycle;
//const uint32 TIME_1S = 1000000;
uint16 T1OvfTimes=0;
void port_init(void)
{
PORTA = 0xFF;
DDRA = 0x00;
PORTB = 0xFF;
DDRB = 0x00;
PORTC = 0xFF; //m103 output only
DDRC = 0x00;
PORTD = 0xFF;
DDRD = 0x00;
}
//TIMER1 initialisation - prescale:1024
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 1Hz
// actual value: 1.000Hz (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1 = 0; //setup
ICR1 = 0;
TCCR1A = 0x00;
TCCR1B = 0x02; //start Timer, Timer source=CLK/8
}
#pragma interrupt_handler timer1_capt_isr:6
void timer1_capt_isr(void)
{
TCCR1B = 0x00; //stop
//frq=(ICR1+86);
//frq=TIME_1S/frq; // read (int)value in ICR1 using
cycle=ICR1-24;
//cycle = 1000000;
if(T1OvfTimes!=0)
cycle += (uint32)T1OvfTimes*65535;
T1OvfTimes = 0;
ICR1=0;
TCNT1=0;
TCCR1B=0X02;
}
#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{
T1OvfTimes++;
}
//call this routine to initialise all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer1_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x24; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialised
}
//
void main(void)
{
init_devices();
DDRA = 0XFF; //set lcd port as output
DDRB = 0X00; //set ICP port as ???
LCD1602_init();
LCD1602_puts(0x80,"Cycle: s ms us");
while(1)
{
LCD1602_putd(0xcf,cycle,7);
//LCD1602_putd(0xcd,cycle/1000,7);
delay50ms(10);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -