📄 avrx.c
字号:
#include"includes.h"
#define LED1_ON PORTA = 0b11111101
#define LED2_ON PORTA = 0b11111011
#define LED3_ON PORTA = 0b11110111
static void portinit(void);
static void uart0_init(void);
AVRX_GCC_TASK(task1,20, 1);
AVRX_GCC_TASK(task2,20, 2);
AVRX_GCC_TASK(task3,20, 3);
/*********************************自定义变量*********************************************/
TimerControlBlock timer1,timer2;
/*****************************************************************************************/
int main(void)
{
AvrXSetKernelStack(0);
MCUCR = 0x00;
TCNT0 = 0xd5;
TCCR0 = 0x06;
TIMSK = 0x01;
portinit();
uart0_init();
AvrXRunTask(TCB(task1)); //任务1
AvrXRunTask(TCB(task2)); //任务2
AvrXRunTask(TCB(task3)); //任务3
Epilog();
while(1);
}
AVRX_SIGINT(SIG_OVERFLOW0)
{
IntProlog(); // Switch to kernel stack/context
TCNT0 = 0xd5;
AvrXTimerHandler(); // Call Time queue manager
Epilog(); // Return to tasks
}
static void portinit(void)
{
PORTA = 0xFF;
DDRA = 0xFF;
PORTB = 0xFF;
DDRB = 0xFF;
PORTC = 0xFF; //m103 output only
DDRC = 0xFF;
PORTD = 0xFF;
DDRD = 0xFF;
PORTE = 0xFF;
DDRE = 0xFF;
PORTF = 0xFF;
DDRF = 0xFF;
PORTG = 0xFF;
DDRG = 0xFF;
}
static void uart0_init(void)
{
UCSR0B = 0x00;
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x05;
UBRR0H = 0x00;
UCSR0B = 0x98;
}
NAKEDFUNC(task1) //任务1:串口发送
{
while (1)
{
SendString("AVRX Test!\n");
AvrXDelay(&timer1,1000);
}
}
NAKEDFUNC(task2) //任务2:LED灯闪烁
{
while (1)
{
LED1_ON;
AvrXDelay(&timer2,200);
LED2_ON;
AvrXDelay(&timer2,200);
LED3_ON;
AvrXDelay(&timer2,200);
}
}
NAKEDFUNC(task3) //任务3:检测按键
{
while (1)
{
switch(Key())
{
case 1:
SendString("Key1\n");
break;
case 2:
SendString("Key2\n");
break;
case 3:
SendString("Key3\n");
break;
case 4:
SendString("Key4\n");
break;
case 5:
SendString("Key5\n");
break;
case 6:
SendString("Key6\n");
break;
case 7:
SendString("Key7\n");
break;
case 8:
SendString("Key8\n");
break;
case 9:
SendString("Key9\n");
break;
case 10:
SendString("Key10\n");
break;
case 11:
SendString("Key11\n");
break;
case 12:
SendString("Key12\n");
break;
case 13:
SendString("Key13\n");
break;
case 14:
SendString("Key14\n");
break;
case 15:
SendString("Key15\n");
break;
case 16:
SendString("Key16\n");
break;
default:
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -