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

📄 44blib.c

📁 S3c44B0x驱动16灰阶240*160液晶屏程式
💻 C
字号:

#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

#include "44b.h"
#include "44blib.h"
#include "def.h"
//#include "option.h"

//--------------------------------SYSTEM---------------------------------//
static int delayLoopCount=400;

void Delay(int time)
// 100us resolution.//
{
	int i;
	for(;time>0;time--)
		for(i=0;i<delayLoopCount;i++);
	//while((rPDATC&0x01)==0x00);
}


void SoftDelay(int ms)//64M, delay about 1ms
{
	int i,j,k;
	for(i=0;i<ms;i++)
	{
		for(j=0;j<256;j++);
		for(k=0;k<256;k++);
	}
}

//------------------------PORTS------------------------------//
void Port_Init(void)
{
	rPCONA = 0x3ff;	

	rPDATB = 0x7ff;
	rPCONB = 0x7ff;	
	
	rPDATC = 0xff0f;	
	rPCONC = 0x00005500;	
	rPUPC  = 0x0000;

	rPDATD= 0xff;
	rPCOND= 0xaaaa;	
	rPUPD = 0x0;	
	
	rPDATE	= 0xff;
	rPCONE	= 0x05428;	
	rPUPE	= 0x19;		

	
	rPDATF = 0x1ff;
	rPCONF = 0x000160;	
	rPUPF  = 0x1ff;	
		
    rPDATG = 0xff;
	rPCONG = 0x0001; 	
	rPUPG  = 0xf7;		
	
	rSPUCR = 0x7;         //D15-D0 pull-up disable
	rEXTINT= 0x0;         //均为低电平触发

}

/************************* UART ****************************/
void Uart_Init(void)
{
    int i;

    rUFCON0=0x0;     //FIFO disable
    rUFCON1=0x0;
    rUMCON0=0x0;
    rUMCON1=0x0;

    rULCON0=0x3;     //Normal,No parity,1 stop,8 bit
    rUCON0=0x245;    //rx=edge,tx=level,disable timeout int.,enable rx error int.,normal,interrupt or polling
    rUBRDIV0=( (int)(MCLK/16./115200 + 0.5) -1 );

    for(i=0;i<100;i++);
}


void Uart_TxEmpty(int ch)
{
		while(!(rUTRSTAT0 & 0x4)); //wait until tx shifter is empty.
}


char Uart_Getch(void)
{
		while(!(rUTRSTAT0 & 0x1)); //Receive data read
		return RdURXH0();
}


char Uart_GetKey(void)
{
	if(rUTRSTAT0 & 0x1)    //Receive data ready
   	    return RdURXH0();
	else
	    return 0xff;
}


void Uart_GetString(char *string)
{
    char *string2=string;
    char c;
    while((c=Uart_Getch())!='\r')
    {
		if(c=='\b')
		{
		    if(	(int)string2 < (int)string )
		    {
				Uart_SendString("\b \b");
				string--;
		    }
		}
		else 
		{
		    *string++=c;
		    Uart_SendByte(c);
		}
    }
    *string='\0';
    Uart_SendByte('\n');
}


void Uart_SendByte(int data)
{
	if(data=='\n')
	{
	    while(!(rUTRSTAT0 & 0x2));
	    Delay(10);	//because the slow response of hyper_terminal 
	    WrUTXH0('\r');
	}
	while(!(rUTRSTAT0 & 0x2)); //Wait until THR is empty.
	Delay(10);
	WrUTXH0(data);
}		


void Uart_SendString(char *pt)
{
    while(*pt)
	Uart_SendByte(*pt++);
}


int Uart_RxReady(void)
{
	return (rUTRSTAT0 & 0x1);	//Receive data ready
}



/************************* General Library **********************/

int _atoi_(char *str)
{
    int n=0;
    char c=1;

    while((c=*str++)&&(c>=0x30)&&(c<=0x39))
            n = n*10 + c-'0';
    return(n);
}

⌨️ 快捷键说明

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