#include #include #include "E:\Atmega128\code\ucos_ii.h" #include "E:\Atmega128\code\app.h" INT8U j=0,k=0; void port_init(void) { PORTA = 0x00; DDRA = 0x11; PORTB = 0x00; DDRB = 0x00; PORTC = 0x00; //m103 output only DDRC = 0x00; PORTD = 0x00; DDRD = 0x00; PORTE = 0x00; DDRE = 0x00; PORTF = 0x00; DDRF = 0x00; PORTG = 0x00; DDRG = 0x00; } //TIMER2 initialize - prescale:1024 // WGM: Normal // desired value: 100Hz // actual value: 100.160Hz (0.2%) void timer2_init(void) { TCCR2 = 0x00; //stop TCNT2 = 0xB2; //setup OCR2 = 0x4E; TCCR2 = 0x05; //start } #pragma interrupt_handler timer2_ovf_isr:11 void timer2_ovf_isr(void) { j++; TCNT2 = 0xB2; //reload counter value if(j%100==0) //溢出中断100次,也就是1秒发送一次消息邮箱 { j=0; OSMboxPost(TestMbox,"OK"); } } //call this routine to initialize all peripherals void init_devices(void) { //stop errant interrupts until set up CLI(); //disable all interrupts XDIV = 0x00; //xtal divider XMCRA = 0x00; //external memory port_init(); timer2_init(); MCUCR = 0x00; EICRA = 0x00; //extended ext ints EICRB = 0x00; //extended ext ints EIMSK = 0x00; TIMSK = 0x40; //timer interrupt sources ETIMSK = 0x00; //extended timer interrupt sources SEI(); //re-enable interrupts //all peripherals are now initialized } // void main(void) { init_devices(); //insert your functional code here... OSInit(); OSTaskCreate(TestTask,(void*)0,&TestTaskStk[TASK_STK_SIZE-1],0); OSStart(); } static void TestTask(void *pdata) { INT8U err; pdata=pdata; #if OS_MBOX_EN > 0 TestMbox = OSMboxCreate((void *)0); #endif OSMboxPend(TestMbox,0,&err); while(1) { k++; PORTA = 0x03; OSTimeDly(10); } }