📄 44blib.c
字号:
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "44b.h"
#include "44blib.h"
#include "option.h"
#include "def.h"
static int whichUart = 0;
U32 aLcdActiveBuffer[LCD_YSIZE][LCD_XSIZE/4];
void Lcd_Clr(void)
{
U32 i;
U32 *pDisp = (U32*)aLcdActiveBuffer;
for (i = 0; i < (SCR_XSIZE * SCR_YSIZE / 4); i++)
{
*pDisp++ = 0xffffffff;
}
}
void Lcd_Init (void)
{
//int i, j;
//int time = 10000*2;
rLCDCON1=(0x0)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);//0x4f40
// disable,8B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
rLCDCON2=(119)|(HOZVAL_COLOR<<10)|(10<<21);
//LINEBLANK=10 (without any calculation)
rLCDSADDR1= (0x3<<27) | ( ((unsigned int)aLcdActiveBuffer>>22)<<21 ) | M5D((unsigned int)aLcdActiveBuffer>>1);
// 256-color, LCDBANK, LCDBASEU
rLCDSADDR2= M5D((((unsigned int)aLcdActiveBuffer+(SCR_XSIZE*LCD_YSIZE)/2)>>1)) | (MVAL<<21);
rLCDSADDR3= (LCD_XSIZE/2) | ( ((SCR_XSIZE-LCD_XSIZE)/2)<<9 );
//The following value has to be changed for better display.
rREDLUT =0xfdb96420;
rGREENLUT=0xfdb96420;
rBLUELUT =0xfb40;
//rDITHMODE=0x0;
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=(0x1)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12); //enable
//rLCDCON1=(0x1)|(2<<5)|(MVAL_USED<<7)|(0x1<<8)|(0x1<<10)|(CLKVAL_COLOR<<12); //enable
rPDATE=0x1fe;
Lcd_Clr();
}
void LCD_PutPixel(int x,int y,int c)
{
aLcdActiveBuffer[(y)][(x)/4]=(( aLcdActiveBuffer[(y)][(x)/4] & (~(0xff000000>>((x)%4)*8)) ) | ( (c)<<((4-1-((x)%4))*8) ));
}
void Port_Init(void)
{
/* PORTA use default */
/* PORTB Led */
rPCONB = 0x1cf;
rPDATB = 0xffff;
/* PORTC pc12:TXD1 pc13:RXD1 pc0:JUMPER */
rPCONC = 0xfffffffc;
/* ALL PULL UP */
rPUPC = 0xffff;
/* PORTD */
rPCOND = 0xaaaa;
rPUPD = 0xff;
/* PORTE */
rPCONE = 0x5568;
rPDATE = 0xd0;
rPUPE = 0x6;
/* PORTF pf0:IICSCL pf1:IICSDA pf5-pf8:Keyboard */
rPCONF = 0xa;
/* Input Pins PULL UP */
rPUPF = 0x1e0;
/* PORTG */
rPCONG=0x5500;
rPDATG=0x0;
}
void Uart_Init(int clk,int baud)
{
/* FIFO disable, MODEM disable */
rUFCON0 = 0x0;
rUFCON1 = 0x0;
rUMCON0 = 0x0;
rUMCON1 = 0x0;
/* Normal,No parity,1 stop,8 bit */
rULCON0 = 0x3;
rUCON0 = 0x205;
rUBRDIV0 = (int)(clk / 16 / baud + 0.5) - 1;
rULCON1 = 0x3;
rUCON1 = 0x205;
rUBRDIV1 = (int)(clk / 16 / 19200 + 0.5) - 1;
}
/******************** Uart_Getch1 *************************/
char Uart_Getch1(void)
{
while(!(rUTRSTAT0 & 0x1));
return rURXH0;
}
/******************** Uart_Getch2 *************************/
char Uart_Getch2(void)
{
while(!(rUTRSTAT1 & 0x1));
return rURXH1;
}
/******************** Uart_Getch_Timeout *****************/
/******************** Uart_SendByte1 **********************/
void Uart_Sendch1(char data)
{
if(data=='\n')
{
while(!(rUTRSTAT0 & 0x2));
/* For the slow response of HT */
Delay(HT_DELAY);
WrUTXH0('\r');
}
while(!(rUTRSTAT0 & 0x2));
Delay(HT_DELAY);
WrUTXH0(data);
}
/******************** Uart_SendByte2 **********************/
void Uart_Sendch2(char data)
{
if(data=='\n')
{
while(!(rUTRSTAT1 & 0x2));
Delay(HT_DELAY);
rUTXH1='\r';
}
while(!(rUTRSTAT1 & 0x2));
Delay(HT_DELAY);
rUTXH1=data;
}
/******************** Uart_SendData1**********************/
void Uart_SendData1(char data)
{
while(!(rUTRSTAT0 & 0x2));
WrUTXH0(data);
}
/******************** Uart_SendData2**********************/
void Uart_SendData2(char data)
{
while(!(rUTRSTAT1 & 0x2));
rUTXH1=data;
}
/******************** Uart_SendString1 **********************/
void Uart_SendString1(char *pt)
{
while(*pt)
Uart_Sendch1(*pt++);
}
/******************** Uart_SendString2 **********************/
void Uart_SendString2(char *pt)
{
while(*pt)
Uart_Sendch2(*pt++);
}
/******************** Uart_Printf1 **********************/
void Uart_Printf1(char *fmt,...)
{
va_list ap;
char string[256];
va_start(ap,fmt);
vsprintf(string,fmt,ap);
Uart_SendString1(string);
va_end(ap);
}
/******************** Uart_Printf2 **********************/
void Uart_Printf2(char *fmt,...)
{
va_list ap;
char string[256];
va_start(ap,fmt);
vsprintf(string,fmt,ap);
Uart_SendString2(string);
va_end(ap);
}
/******************** Uart_GetString **********************/
/******************** Uart_GetIntNum **********************/
/******************** Uart_Flush1 **********************/
int Uart_Flush1(void)
{
char temp;
if(rUTRSTAT0 & 0x1)
{
temp = RdURXH0();
return 1;
}
else
return 0;
}
/******************** Uart_Flush2 **********************/
int Uart_Flush2(void)
{
char temp;
if(rUTRSTAT1 & 0x1)
{
temp = RdURXH1();
return 1;
}
else
return 0;
}
/************************* Delay *************************/
void Delay(int time)
{
int counter=time*400;
while(counter--);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -