?? control.c
字號(hào):
//ICC-AVR application builder : 2006-12-10 17:22:46
// Target : M8
// Crystal: 8.0000Mhz
//ICC-AVR application builder : 2006-12-10 21:46:41
// Target : M8
// Crystal: 8.0000Mhz
#include <iom8v.h>
#include <macros.h>
long Ddummy,Counter_MotorSpeedPulse,Counter_IRPulse,Settings_IRTopValue;
char Settings_PrintQuality;
const FTC2 =64;
void port_init(void)
{
PORTB = 0x00;
DDRB = 0xFF;
PORTC = 0x7F; //m103 output only
DDRC = 0x00;
PORTD = 0xFF;
DDRD = 0x00;
}
//TIMER1 initialisation - prescale:1
// WGM: 4) CTC, TOP=OCRnA
// desired value: 1KHz
// actual value: 1.000KHz (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1 = 0x00; //setup
ICR1H = 0x1F;
ICR1L = 0x3F;
OCR1A = FTC2*Settings_PrintQuality; //每組Settings_PrintQuality個(gè)墨滴選一個(gè)充電
OCR1B = FTC2/2; //充電脈寬是墨滴周期時(shí)間的一半,充電相位為0,充電好壞由斷點(diǎn)調(diào)整
TCCR1A = 0x50;
TCCR1B = 0x09; //start Timer
}
//
#pragma interrupt_handler timer1_compa_isr:7
void timer1_compa_isr(void) //開始一個(gè)新的充電墨滴時(shí)PB1開始產(chǎn)生一個(gè)下降沿或上升沿
{ //compare occured TCNT1=OCR1A
//if(PINB1==0){ //如果PB1是低電平,就開始一個(gè)新的DA轉(zhuǎn)換
// ;
//}
}
#pragma interrupt_handler timer1_compb_isr:8
void timer1_compb_isr(void) //停止充電時(shí)刻,PB2開始產(chǎn)生上升沿或下降沿
{
//compare occured TCNT1=OCR1B
}
//
//TIMER2 initialisation - prescale:1
// WGM: Normal
// desired value: 62.5KHz
// actual value: 62.5KHz (0.0%)
void timer2_init(void)
{
TCCR2 = 0x00; //stop
ASSR = 0x00; //set async mode
TCNT2 = 0x00; //setup
OCR2 = FTC2; //0x40;振蕩頻率的分頻值,8M-64,4M-32
TCCR2 = 0x19; //CTC 模式
}
#pragma interrupt_handler int0_isr:2
void int0_isr(void) //external interupt on INT0 記錄電機(jī)速度
{
Counter_MotorSpeedPulse++;
if(Counter_MotorSpeedPulse>=1000){ //計(jì)算并顯示電機(jī)速度
Counter_MotorSpeedPulse =0;
PORTB |=32; //PB5腳置高電平
}
if(Counter_MotorSpeedPulse==500) PORTB &=223; //PB5腳置低電平
}
#pragma interrupt_handler int1_isr:3
void int1_isr(void) //external interupt on INT1 記錄光電開關(guān)的觸發(fā)脈沖
{
Counter_IRPulse++;
if(Counter_IRPulse >= 1000){ //計(jì)算并觸發(fā)打印按鈕
Counter_IRPulse=0;
PORTB |=64; //PB6腳置高電平
}
if(Counter_IRPulse == 500) PORTB &=191; //PB6腳置低電平
}
//call this routine to initialise all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer2_init();
timer1_init();
MCUCR = 0x0F;
GICR = 0xC0;
TIMSK = 0x18; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialised
}
void main()
{
Settings_IRTopValue = 1000; //光電開關(guān)觸發(fā)Settings_IRTopValue次后就開始打印一條信息
Settings_PrintQuality = 10; //10個(gè)墨滴選一個(gè)充電
Counter_MotorSpeedPulse =0;
Counter_IRPulse =0;
init_devices();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -