⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 AVRGCC编写的很好用的串口通讯源程序
💻 C
字号:
#include <stdio.h>
#include <string.h>
#include <avr/io.h>
#include <avr/pgmspace.h>

#include <avrx/avrx.h>

//#include "hardware.h"
#include "uart.h"

Mutex key_pressed;
TimerControlBlock delay;

// 1ms
AVRX_SIGINT(SIG_OVERFLOW0) 
{
	IntProlog();
    TCNT0 = (0xFF - F_CPU / 256 / 1000);//TCNT0_INIT;
	AvrXTimerHandler();
	Epilog();
}

AVRX_SIGINT(SIG_INTERRUPT0) 
{
	IntProlog();
	AvrXSetSemaphore(&key_pressed);
	Epilog();
}

AVRX_GCC_TASKDEF(KeyPress, 100, 5)
{
	MCUCR |= _BV(ISC01) | _BV(ISC00);
	GIFR |= _BV(INTF0);
	GICR |= _BV(INT0);
	
	while(1)
	{
		while(1)
		{
			AvrXResetSemaphore(&key_pressed);
			AvrXWaitSemaphore(&key_pressed);
			AvrXDelay(&delay, 20);
			if (PIND & _BV(PD2)) break;
		}
		puts_P(PSTR("key bn中国 pool pressed!\r"));
	}
}

AVRX_GCC_TASKDEF(Display, 100, 5)
{
	DDRB |= _BV(PB1);
	
	while(1)
	{
		puts_P(PSTR("0123456789中华人民共和国万岁!\r"));
		PORTB &= ~_BV(PB1);
		AvrXDelay(&delay, 20);
		PORTB |= _BV(PB1);
		AvrXDelay(&delay, 980);
	}
}

int
main(void)
{
	//OSCCAL = 0xB7;

	AvrXSetKernelStack(0);

	// Analog Comparator initialization
	// Analog Comparator: Off
	// Analog Comparator Input Capture by Timer/Counter 1: Off
	// Analog Comparator Output: Off
	ACSR = 0x80;
	SFIOR = 0x00;

	TCCR0 = _BV(CS02);//T0MC8_CK256; 	// Set up Timer0 for CLK/256 rate
	TCNT0 = (0xFF - F_CPU / 256 / 1000);//TCNT0_INIT;
	TIMSK |= _BV(TOIE0);  	// Enable Timer0 overflow interrupt

	UartInit();
	
	AvrXRunTask(TCB(Display));
	AvrXRunTask(TCB(KeyPress));

    Epilog();                   // Switch from AvrX Stack to first task

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -