📄 main._c
字号:
//在主程序中进行数据转换;
//ICC-AVR application builder : 2005-3-29 下午 11:17:39
// Target : M8
// Crystal: 11.059Mhz
#include <iom8v.h>
#include <macros.h>
//定义全局变量;
char flag = 0;
char data = 90;
void port_init(void)
{
PORTB = 0xFF;
DDRB = 0x02;
PORTC = 0x7F; //m103 output only
DDRC = 0x00;
PORTD = 0xFF;
DDRD = 0x00;
}
//TIMER1 initialisation - prescale:8
// WGM: 14) PWM fast, TOP=ICRn
// desired value: 50Hz
// actual value: 50.001Hz (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0x00; //setup
TCNT1L = 0x00;
OCR1AH = 0x08;
OCR1AL = 0x19;
OCR1BH = 0x08;
OCR1BL = 0x19;
ICR1H = 0x6B;
ICR1L = 0xFE;
TCCR1A = 0xA2;
TCCR1B = 0x1A; //start Timer
}
//UART0 initialisation
// desired baud rate: 9600
// actual: baud rate:9600 (0.0%)
// char size: 8 bit
// parity: Disabled
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = 0x86;
UBRRL = 0x47; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0x98;
}
#pragma interrupt_handler uart0_rx_isr:12
void uart0_rx_isr(void)
{
//uart has received a character in UDR
data= UDR;
//UDR = data;
flag = 1;
}
//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();
uart0_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x04; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialised
}
//
void main(void)
{
unsigned int time;
init_devices();
//insert your functional code here...
while(1)
{
if(flag == 1)
{
time = data *31;
time = (time>>1)+691;
OCR1AH = time >>8;
OCR1AL = time;
flag = 0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -