📄 main.c.bak
字号:
#include "..\startup\44b.h"#include "..\inc\44blib.h"#include "..\startup\option.h"#include "..\inc\def.h"#include "..\ucos\includes.h"/*lcd显示代码*/#define PPort (*(volatile unsigned char *)(0xa000000))#define HZK24 ((volatile unsigned char *)(0x172A00))#define LCD_ACTIVE_BUFFER 0xc200000#define SCR_XSIZE (640) #define SCR_YSIZE (480)#define FONT_EN_5_7 0x00#define FONT_EN_8_16 0x01#define FONT_CN_12_12 0x02#define FONT_CN_16_16 0x03#define FONT_CN_24_24 0x04#define MVAL_USED 0#define CLKVAL_G16 (6)#define LCD_XSIZE (640)#define LCD_YSIZE (480)#define HOZVAL (LCD_XSIZE/4-1)//softmcu#define LINEVAL (LCD_YSIZE/2-1)#define MVAL (0)#define LCD_ACTIVE_BUFFER 0xc200000#define M5D(n) ((n) & 0x1fffff)#define LCD_PutPixel(x, y, c)\ (*(unsigned char *)(LCD_ACTIVE_BUFFER+ (y) * SCR_XSIZE / 2 + ((x)*4)/8)) = \ ((*(unsigned char *)(LCD_ACTIVE_BUFFER+ (y) * SCR_XSIZE / 2 + ((x)*4)/8)) & \ (~(0xf0 >> (((x)*4)%8))))|((c)&(0xf0 >> (((x)*4)%8)))//Task definition/* allocate memory for tasks' stacks */extern const char g_auc_HZK24s[];/* Global Variable */void Lcd_Init (void){ rDITHMODE=0x12210; rDP1_2 =0xa5a5; rDP4_7 =0xba5da65; rDP3_5 =0xa5a5f; rDP2_3 =0xd6b; rDP5_7 =0xeb7b5ed; rDP3_4 =0x7dbe; rDP4_5 =0x7ebdf; rDP6_7 =0x7fdfbfe; rLCDCON1=(0x0)|(1<<1)|(0<<5)|(MVAL_USED<<7)|(0x0<<8)|(0x0<<10)|(CLKVAL_G16<<12); //softmcu rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21); rLCDCON3=0; rLCDSADDR1= (0x2<<27) | ( ((LCD_ACTIVE_BUFFER>>22)<<21 ) | LCD_ACTIVE_BUFFER>>1); rLCDSADDR2= M5D(((LCD_ACTIVE_BUFFER+(SCR_XSIZE*LCD_YSIZE/2/2))>>1)) | (MVAL<<21)|(1<<29);//softmcu rLCDSADDR3= (LCD_XSIZE/4) | ( ((SCR_XSIZE-LCD_XSIZE)/4)<<9 ); //rLCDCON1=(0x1)|(1<<1)|(0<<5)|(MVAL_USED<<7)|(0x0<<8)|(0x0<<10)|(CLKVAL_G16<<12); //softmcu // enable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk, rPDATE=0xfe;}void Lcd_DspHz24(unsigned short x0, unsigned short y0, unsigned char ForeColor, char *s){ short int i,j,k,x,y,xx; unsigned char qm,wm; unsigned int ulOffset; char hzbuf[72],temp[2]; for(i = 0; i < strlen((const char*)s); i++) { if(((unsigned char)(*(s+i))) < 161) { temp[0] = *(s+i); temp[1] = '\0'; break; } else { qm = *(s+i) - 176;//161; wm = *(s+i + 1) - 161; ulOffset = (unsigned int)(qm * 94 + wm) * 72; for (j = 0; j < 72; j ++) { hzbuf[j] = g_auc_HZK24s[ulOffset + j]; hzbuf[j] =HZK24[ulOffset + j]; } for(y = 0; y < 24; y++) { for(x = 0; x < 24; x++) { k = x % 8; if (hzbuf[y * 3 + x / 8] & (0x80 >> k)) { xx = x0 + x + i*12; LCD_PutPixel( xx, y + y0, (unsigned char)ForeColor); } } } /* for(x=0;x<24;x++) { for(y=0;y<24;y++) { k = y%8; if( hzbuf[x*3+y/8] & (0x80 >> k) ) { xx = x0+x+i*8; LCD_PutPixel(xx,y+y0,(unsigned char)ForeColor); } } }*/ i++; } } }void OutTextXY(unsigned short x0, unsigned short y0, unsigned char Font, unsigned char ForeColor,char * s){ switch(Font) { case FONT_EN_5_7: case FONT_EN_8_16: case FONT_CN_12_12: case FONT_CN_16_16: case FONT_CN_24_24: Lcd_DspHz24(x0,y0,ForeColor,s); break; } }void Lcd_Clr(void){ unsigned int i; unsigned int *pDisp = (unsigned int *)0xc200000; for (i = 0; i < (SCR_XSIZE * SCR_YSIZE / 2 / 4); i++) { *pDisp++ = 0; }}void SetVeeVal(unsigned char Val){ rPDATC = rPDATC & 0x7fff; PPort=Val; rPDATC = rPDATC | 0x8000; }void Delay1(int time)// time=0: adjust the Delay function by WatchDog timer.//// time>0: the number of loop time//// 100us resolution.//{ int i;// if(time==0)// {// time=200;// adjust=1;// delayLoopCount=400;// rWTCON=((MCLK/1000000-1)<<8)|(2<<3); // 1M/64,Watch-dog,nRESET,interrupt disable//// rWTDAT=0xffff;// rWTCNT=0xffff; // rWTCON=((MCLK/1000000-1)<<8)|(2<<3)|(1<<5); // 1M/64,Watch-dog enable,nRESET,interrupt disable //// } for(;time>0;time--) for(i=0;i<400;i++);// if(adjust==1)// {// rWTCON=((MCLK/1000000-1)<<8)|(2<<3);// i=0xffff-rWTCNT; // 1count/16us?????????//// delayLoopCount=8000000/(i*64); //400*100/(i*64/200) //// }}void Beep(void){ rPDATE=rPDATE&0x1f7; Delay1(1000); rPDATE=rPDATE|0x8;}/*lcd显示代码结束*/extern void OSSchedLock(void);#define IRQ_VECTOR_OFFSET (0x18)//-------------------------------------------------------// globle variables//-------------------------------------------------------volatile static int isrCount = 0; // tick counter//volatile static unsigned int Dump_Pool[16];//-------------------------------------------------------// OS_Tick Hook Fubction//-------------------------------------------------------void tick_hook(void){ isrCount++; rI_ISPC = (unsigned int)1 << 20;}//-------------------------------------------------------// install a new ISR// this function must be synchronized//-------------------------------------------------------unsigned int ISR_Install(unsigned int offset, void *pf_ISR){ unsigned int pOldEntry; // get absolute address of IRQ vector // _ISR_STARTADDRESS : see Option.h offset += _ISR_STARTADDRESS; // get the Old ISR service routine entry point pOldEntry = *((unsigned int *)offset); // install new interrupt service routine *((unsigned int *)offset) = (unsigned int)pf_ISR; return pOldEntry;}//-------------------------------------------------------// must be synchronized//-------------------------------------------------------void tick_off(void){ rRTCCON = (unsigned char)1; rTICNT = (unsigned char)0; rRTCCON = (unsigned char)0;}//--------------------------------------------------------// set or clear TICK interrupt mask// this function must be synchronized//--------------------------------------------------------void tick_int_enable(unsigned char bEnabled){ // clear interrupt pending first rI_ISPC = (unsigned int)0x01 << 20; rINTMSK &= (unsigned int)~(0x01 << 20);}//--------------------------------------------------------// start tick function of RTC// interval = (1 + div) / 128 second// this function must be synchronized// div MUST >= 1 && <= 128//--------------------------------------------------------void tick_init(unsigned char div){ rRTCCON = (unsigned char)1;// ASSERT(div >= 1 && div <= 127); rTICNT = (unsigned char)(div | 0x80); rRTCCON = (unsigned char)0; tick_int_enable(1);}//--------------------------------------------------------// interrupt controler initilization//--------------------------------------------------------void intcon_init(void){ rINTMOD = 0; // all interrupt sources configed as IRQ rI_ISPC = 0x7ffffff; // clear all intrrupt request rINTCON = 0x05; // irq interrupt available}//--------------------------------------------------------// globel interrupt enable//--------------------------------------------------------void globle_int_enable(unsigned char bEnabled){ if(bEnabled) rINTMSK &= ~(0x03 << 26); else rINTMSK |= 0x01 << 26;}__inline void Sleep(INT16U uSec){ OSTimeDly((INT16U) (uSec));}void sys_init(void){ tick_off(); tick_int_enable(0); globle_int_enable(0); intcon_init(); isrCount = 0; // Set the function of the pins Port_Init(); Uart_Init(0, 115200); // hook the tick ISR ISR_Install(IRQ_VECTOR_OFFSET, (void *)OSTickISR); globle_int_enable(1);}#define printf Uart_Printf//**********************************************************// THE MAIN FUNCTION BODY//**********************************************************#define N_TASKS 9 // Number of tasks#define TASK_STK_SIZE 1024 // Stack size, in sizeof OS_STK, or int 32bitOS_STK TaskStk[N_TASKS][TASK_STK_SIZE]; // Tasks stacksvoid Task1(void *);void Task2(void *);void Task3(void *);void Task4(void *);void Task5(void *);void Task6(void *);void Task7(void *);int Main(int argc, char **argv){ int task_1 = 0, task_2 = 1,task_3=2,task_4=3,task_5=4,task_6=5,task_7=6,i; sys_init(); /*a3000显示初始化*/ rSYSCFG=0xE; // Using 8KB Cache// Port_Init(); Lcd_Init(); rLCDCON1|=0x00000001; SetVeeVal(0xff); //uHALr_InitInterrupts(); Lcd_Clr(); for(i=0;i<20;i++) { OutTextXY(i*24, i*24, 0x04,0xff, "车博士世界吗器好"); Delay(1000); Beep(); } Lcd_Clr(); /*a3000显示初始化END*/ Uart_Printf("\n ### Main Starts !\n"); OSInit(); OSTaskCreate(Task1, &task_1, &TaskStk[0][TASK_STK_SIZE-1], 1); OSTaskCreate(Task2, &task_2, &TaskStk[1][TASK_STK_SIZE-1], 2); OSTaskCreate(Task3, &task_3, &TaskStk[3][TASK_STK_SIZE-1], 3); OSTaskCreate(Task4, &task_4, &TaskStk[4][TASK_STK_SIZE-1], 4); OSTaskCreate(Task5, &task_5, &TaskStk[5][TASK_STK_SIZE-1], 5); OSTaskCreate(Task6, &task_6, &TaskStk[6][TASK_STK_SIZE-1], 6); OSTaskCreate(Task7, &task_7, &TaskStk[7][TASK_STK_SIZE-1], 7); OSStart(); return 0;}void Task1(void * pParam){ //Uart_Printf(" @@@ Task1 will starts time ticker !\n"); // enable Ticker, 16 ticks per second tick_init(7); // why start tick here? see uCOS-II Doc Chapter 8 : /* "You MUST enable ticker interrupts AFTER multitasking has started, i.e. after calling OSStart(). In other words, you should initialize and tick interrupts in the first task that executes following a call to OSStart(). A common mistake is to enable ticker interrupts between calling OSInit() and OSStart() ..." */ while(1) { OSSchedLock(); /*printf( "@@@\n"); printf( "@@@ task 1 running ... \n" ); printf( "@@@ Q__Q \n" ); printf( "@@@ /____\\ \n" ); printf( "@@@ \\____/ \n" ); printf( "@@@ /\\/\\ \n" ); printf( "@@@ __(\\\\//)__ \n" ); printf( "@@@ >__/w w\\__< \n" ); printf( "@@@\n" ); printf( "@@@ go to sleep 10 time-ticks\n" ); printf( "@@@\n" );*/ OutTextXY(2*24, 2*24, 0x04,0xff, "车博士解码器好一"); Delay1(100); OSSchedUnlock(); Sleep(10); }}void Task2(void * pParam){ while(1) { OSSchedLock(); /*printf( "+++ \n" ); printf( "+++ task 2 running ... \n" ); printf( "+++ ╭︿︿︿╮ \n" ); printf( "+++ {/ o o \\} \n" ); printf( "+++ ( (oo) ) \n" ); printf( "+++ ︶ \n" ); printf( "+++ \n" ); printf( "+++ go to sleep 5 time-ticks\n" ); printf( "+++ \n" );*/ OutTextXY(1*24, 1*24, 0x04,0xff, "车博士世界吗器好二"); Delay1(100); //Lcd_Clr(); OSSchedUnlock(); Sleep(10); }}void Task3(void * pParam){ while(1) { OSSchedLock(); OutTextXY(1*24, 3*24, 0x04,0xff, "车博士解码器好不好三"); Delay1(100); OSSchedUnlock(); Sleep(10); }}void Task4(void * pParam){ while(1) { OSSchedLock(); OutTextXY(1*24, 4*24, 0x04,0xff, "车博士解码器好不好四"); Delay1(100); //Lcd_Clr(); OSSchedUnlock(); Sleep(10); }}void Task5(void * pParam){ while(1) { OSSchedLock(); OutTextXY(1*24, 5*24, 0x04,0xff, "车博士解码器好不好五"); Delay1(100); //Lcd_Clr(); OSSchedUnlock(); Sleep(10); }}void Task6(void * pParam){ while(1) { OSSchedLock(); OutTextXY(1*24, 6*24, 0x04,0xff, "车博士解码器好不好六"); Delay1(100); //Lcd_Clr(); OSSchedUnlock(); Sleep(10); }}void Task7(void * pParam){ while(1) { OSSchedLock(); OutTextXY(1*24, 7*24, 0x04,0xff, "车博士解码器好不好七"); Delay1(100); Lcd_Clr(); OSSchedUnlock(); Sleep(10); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -