|
以下蓝色文字由站长:armok 于:2009-03-15,08:36:10 加入。 贴子很好,但需要补充一些材料才能置成酷贴
谢谢你的共享。只是一堆源代码,没有电路图会大幅降低帖子的交流效果。
请将电路图也上传上来,这样本贴就能置COOL,会有更多的人关注,并且能获得本论坛的专家分数(迟些会实施)
你可以编辑本贴上传电路图,或在后面的回复里上传。谢谢对我们网站的支持。
/*这是本人设计的收音机的程序,实际使用效果良好,有时钟,闹钟,红外遥控,频率显示存储功能
用万能板搭的电路,没有画电路图呢,就暂不提供了。关键元件如下:
1602液晶显示屏,TEA5767 FM收音机芯片,ATMEGA16,32768HZ晶振。
CPU时钟1000000HZ
ICCAVR环境编译后占用13K空间,源代码如下:
*/
/*
*************************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* ATmega128 Sample code
*
* File : APP.C
* By : Jean J. Labrosse
*************************************************************************************************************
*/
#include "includes.h"
/*
**************************************************************************************************************
* CONSTANTS
*
* Note(s) : 1) See OS_CFG.H for the default stack size: 'OS_TASK_STK_SIZE'
**************************************************************************************************************
*/
#define CPU_CLK_FREQ 1000000L
#define OS_TASK_0_STK_SIZE OS_TASK_STK_SIZE
#define OS_TASK_0_HARD_STK_SIZE OS_TASK_HARD_STK_SIZE
#define OS_TASK_1_STK_SIZE OS_TASK_STK_SIZE
#define OS_TASK_1_HARD_STK_SIZE OS_TASK_HARD_STK_SIZE
#define light PORTDBIT.bit3 //LCD backlight
#define power PORTDBIT.bit4 //power
/*
**************************************************************************************************************
* VARIABLES
**************************************************************************************************************
*/
OS_STK AppTask0Stk[OS_TASK_0_STK_SIZE];
OS_STK AppTask1Stk[OS_TASK_1_STK_SIZE];
OS_EVENT *CMDMbox;
unsigned char menu, second_tick;
const char station[][5] = {
0x29,0x59,0xF8,0x56,0x80, //power off
0x2B,0x80,0xF8,0x16,0x80, //campus band low limit,76MHZ
0x33,0x9B,0xF8,0x16,0x80, //campus band up limit,91MHZ
0x29,0xD4,0xF8,0x16,0x80, //china band low limit,87.5MHZ
0x33,0x9B,0xF8,0x16,0x80, //china band up limit,108MHZ
0x2A,0x11,0xF8,0x16,0x80, //88MHZ
0x2A,0x8A,0xF8,0x16,0x80, //89MHZ
0x2B,0x05,0xF8,0x16,0x80, //90MHZ
0x2F,0xCA,0xF8,0x16,0x80}; //100MHZ
/*
**************************************************************************************************************
* FUNCTION PROTOTYPES
**************************************************************************************************************
*/
static void AppTaskCreate(void);
static void AppTask0(void *);
static void AppTask1(void *);
static void AppIOInit(void);
/*
**************************************************************************************************************
* MAIN
*
* Note(s): 1) You SHOULD use OS_TASK_STK_SIZE (see OS_CFG.H) when setting OSTaskStkSize prior to calling
* OSInit() because OS_TASK_IDLE_STK_SIZE and OS_TASK_STAT_STK_SIZE are set to this value in
* OS_CFG.H.
**************************************************************************************************************
*/
void main (void)
{
/*---- Any initialization code prior to calling OSInit() goes HERE --------------------------------*/
/* IMPORTANT: MUST be setup before calling 'OSInit()' */
OSTaskStkSize = OS_TASK_STK_SIZE; /* Setup the default stack size */
OSTaskHardStkSize = OS_TASK_HARD_STK_SIZE; /* Setup the default hardware stack size */
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
/*---- Any initialization code before starting multitasking ---------------------------------------*/
OSTickISR_Init(); // Initialize the ticker
AppIOInit(); /* Initialize the I/Os */
Init_LCD();
LCD_WriteControl(LCD_CLEAR);
LCD_Cursor(1,1);
LCD_DisplayString("Welcome enjoy it");
delay_ms(2000);
light = 0;
menu = 0;
menu9(0);
CMDMbox = OSMboxCreate((void*)0);
AppTaskCreate();
/*---- Create any other task you want before we start multitasking --------------------------------*/
OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
}
/*
*********************************************************************************************************
* CREATE APPLICATION TASKS
*
* Description : This function creates the application tasks.
*
* Arguments : p_arg is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppTaskCreate (void)
{
/*---- Task initialization code goes HERE! --------------------------------------------------------*/
OSTaskStkSize = OS_TASK_0_STK_SIZE; /* Setup the default stack size */
OSTaskHardStkSize = OS_TASK_0_HARD_STK_SIZE; /* Setup the default hardware stack size */
OSTaskCreate(AppTask0, (void *)0, (OS_STK *)&AppTask0Stk[OSTaskStkSize - 1], 0);
/*---- Task initialization code goes HERE! --------------------------------------------------------*/
OSTaskStkSize = OS_TASK_1_STK_SIZE; /* Setup the default stack size */
OSTaskHardStkSize = OS_TASK_1_HARD_STK_SIZE; /* Setup the default hardware stack size */
OSTaskCreate(AppTask1, (void *)0, (OS_STK *)&AppTask1Stk[OSTaskStkSize - 1], 1);
}
/*
*********************************************************************************************************
* TASK #0
*********************************************************************************************************
*/
static void AppTask0(void *p_arg)
{
unsigned char *cmd;
p_arg = p_arg; /* Prevent compiler warnings */
while (TRUE) {
#if OS_CRITICAL_METHOD == 3 //Allocate storage for CPU status register
OS_CPU_SR cpu_sr;
#endif
//OS_ENTER_CRITICAL();
cmd = (INT8U*)OSMboxAccept(CMDMbox);
if(cmd){
if(*cmd==1)
key_control(*(cmd+1));
else if(*cmd==2)
ir_control(*(cmd+1));
}
dis_time();
//OS_EXIT_CRITICAL();
OSTaskSuspend(OS_PRIO_SELF);
//OSTimeDly(OS_TICKS_PER_SEC/2);
}
}
/*
*********************************************************************************************************
* TASK #1
*********************************************************************************************************
*/
static void AppTask1(void *p_arg)
{
unsigned char n, light_timer, cmd[2]={0,0};
p_arg = p_arg;
light_timer = 10;
while (TRUE) {
#if OS_CRITICAL_METHOD == 3 //Allocate storage for CPU status register
OS_CPU_SR cpu_sr;
#endif
//OS_ENTER_CRITICAL();
cmd[1] = press_key();
if(cmd[1]){
cmd[0] = 1; //identify key input
light = 0;
light_timer = 10;
OSMboxPost(CMDMbox,(void*)cmd);
OSTaskResume(0);
}
n=20;
while(n--){ //when no control, active task0 per tick
cmd[1] = IR_cmd();
if(cmd[1]){
cmd[0] = 2; //identify infrared
light = 0;
light_timer = 10;
OSMboxPost(CMDMbox,(void*)cmd);
OSTaskResume(0);
}
}
time:
while(second_tick){
if(light_timer)
light_timer--;
else
light = 1;
second_tick--;
clock();
if(!second)
alarm();
OSTaskResume(0);
}
//OS_EXIT_CRITICAL();
}
}
/*
*********************************************************************************************************
* SETUP THE I/Os
*********************************************************************************************************
*/
static void AppIOInit (void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x07; //按钮三个
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x03; //LCD RW RS
PORTD = 0x00;
DDRD = 0x98; //LCE EN,LCD light,power
light = 1; //LCD 背光
power = 1;
}
/*
*********************************************************************************************************
* SETUP THE TICK RATE
*********************************************************************************************************
*/
//TIMER2 initialize - prescale:128
//TIMER2 CLOCK: 32768HZ
// WGM: Normal
// desired value: 1Hz
// actual value: 1.000Hz (0.0%)
void OSTickISR_Init(void)
{
TCCR2 = 0x00; //stop
ASSR = 0x08; //set async mode
TCCR2 = 0x05; //start
TIMSK = 0x40;
}
void OSTickISR_Handler (void)
{
//TCNT2 = 256 - (CPU_CLK_FREQ / OS_TICKS_PER_SEC / 256);
//light ^= 1;
second_tick++;
OSTimeTick();
} |
|