📄 44blib.c
字号:
/************************************************
* NAME : 44BLIB.C *
* Version : 17.APR.00 *
************************************************/
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#include "lcd.h"
#include "lcdlib.h"
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#define STACKSIZE 0xa00
//SVC satck size(do not use user stack)
#define HEAPEND (_ISR_STARTADDRESS-STACKSIZE-0x500) // = 0xc7ff000
//SVC Stack Area:0xc(e)7ff000-0xc(e)7ffaff
//#define DBUFgprslen 0x500
U8 Dgprs[DBUFgprslen]; // for gprs
//#define DBUFgpslen 0x1000
U8 Dgps[DBUFgpslen]; // for gps
U8 DBUFA[0x1000]; //temp
U8 DBUFB[0x1000]; //temp
U8 DBUF0[0x100F]; // for cpu serial (4K+9)*2 byte for one frame of cpu
U8 DBUF1[0x100F]; // for cpu serial
U8 count_timer0_overflow=0; //count for T0
U8 count_time; //time over for sending to server
U8 Top_Count_T0_Overflow=80; //Top of count for T0
U8 switch_display_16s,bool_arrive_16s;
U8 bool_start_count=0;
U8 bool_arrive_8s=0;
U8 display_time_arrive=1;
U8 check_key_time_arrive=1;
U8 Display_Which_Screen=0;
U16 MenuStatus=0;
//************************************************************************
extern char *date[8] = {" ","日","一","二","三","四","五","六"};
volatile U32 sec_tick;
U8 date_t[7]={0x05,0x07,0x11,0x18,0x37,0x10,0x02}; //year=2005 month=01 day=01 hour=08 minute=0 second=0 week=7 周六
U8 buff[6];
U8 Status=0;
U8 Screen_Y_Offset=3;
U16 Font1616[0x48000];
U32 UART_BAUD = 115200 ; //串口波特率设定
U32 MCLK = 60000000; //系统主频设定
extern char Image$$RW$$Limit[];
void *mallocPt=Image$$RW$$Limit;
//******************************************************************************
static int delayLoopCount=400;
//从FLASH调字库进入SDRAM中
void Sysloader_LoadFont1616(void)
{
unsigned short int *p,d;
unsigned int i;
p = (unsigned short int*)P_FONT1616;
for( i = 0 ; i < 0x48000 ; i++ ) //00-0x8f,即:0x90个4K
{
d = *p;
Font1616[i] = d>>8 | d << 8;
p++;
}
}
//从FLASH调信息进入SDRAM中
void read_flash_to_ram(U32 sourcestartaddr,U8 *buffer, U16 deststartaddr, U16 movelen)
{
U16 i,d,*p;
p = (U16 *)sourcestartaddr;
for (i=0;i<movelen;i+=2)
{ d=*p;
*((U16*)(buffer+deststartaddr+i))= d;
p++;
}
}
//从SDRAM存信息进入FLASH中
void write_ram_to_flash(U8 *buffer, U16 sourcestartaddr, U32 deststartaddr, U16 movelen)
{
U16 i,j;
U8 *p;
p = (U8 *)deststartaddr;
for (i=0;i<movelen;i+=2)
{ j=*(buffer+sourcestartaddr+i) | (*(buffer+sourcestartaddr+i+1))<<8;
SST39LF160_ProgFlash( deststartaddr+i, j);
}
}
void Delay(int time)
// time=0: adjust the Delay function by WatchDog timer.
// time>0: the number of loop time
// 100us resolution.
{
int i,adjust=0;
if(time==0)
{
time=200;
adjust=1;
delayLoopCount=400;
rWTCON=((MCLK/1000000-1)<<8)|(2<<3); //MCLK/1M,Watch-dog disable,1/64,interrupt disable,reset disable
rWTDAT=0xffff;//for first update
rWTCNT=0xffff;//resolution=64us @any MCLK
rWTCON=((MCLK/1000000-1)<<8)|(2<<3)|(1<<5); //Watch-dog timer start
}
for(;time>0;time--)
for(i=0;i<delayLoopCount;i++);
if(adjust==1)
{
rWTCON=((MCLK/1000000-1)<<8)|(2<<3);//Watch-dog timer stop
i=0xffff-rWTCNT; //1count->64us, 200*400 cycle runtime = 64*i us
delayLoopCount=8000000/(i*64); //200*400:64*i=1*x:100 -> x=80000*100/(64*i)
}
}
//******************************************************************************
//******************************************************************************
void Port_Init(void)
{
//SMDK41100 B/D Status
//LED D5 D6
// PB9 PB10
//S/W S4 S5
// PG5 PG4
//CAUTION:Follow the configuration order for setting the ports.
// 1) setting value
// 2) setting control register
// 3) configure pull-up resistor.
//16bit data bus configuration
//PORT A GROUP
//ADDR24 ADDR23 ADDR22 ADDR21 ADDR20 ADDR19 ADDR18 ADDR17 ADDR16 ADDR0
// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
rPDATA=0x3ff; //All I/O Is High
rPCONA=0x1ff; //ADDR24 is not used,so is IO and OUTPUT
//PORT B GROUP
//rPCONB[10:0]
//|BIT10|....................................................|BIT0
//|nGCS5|nGCS4|nGCS3|nGCS2|nGCS1 |nWBE3 |nWBE2|nSRAS|nSCAS|SCLK|SCKE
//|LEDG |LEDR |n8019|LED |MCSVRAM|POWOFF|BUZA |nSRAS|nSCAS|SCLK|SCKE
//rPCONB
//| 0| 0| 1| 0| 1| 0 | 0| 1| 1| 1| 1
//rPDATB
//| 1| 1| 1| 0| 1| 1 | 0| 1| 1| 1| 1
// 亮 亮 亮 不关机 不响
rPCONB=0x14f;
rPDATB=0x76f; //All I/O Is High
//PORT C GROUP
//BUSWIDTH=16
//PORT C GROUP
//rPCONC[31:0]
//00- input 01-output 10-data 11-function
//|GPC15|............................GPC9GPC8.........GPC5GPC4...............|GPC0
//|BIT31|....................................................................|BIT0
//|MAST CLK|TxEN|RXD1|TXD1|LOCK| CS2| CS1| RS|LCD7|LCD6|LCD5|LCD4|LCD3|LCD2|LCD1|LCD0
//rPCONC
//| 01| 01| 11| 11| 01| 01| 01| 01| 01| 01| 01| 01| 01| 01| 01| 01
//rPDATC[15:0]
//| 1| 0| 1| 1| 0| 0| 0| 1| 1| 1| 1| 1| 1| 1| 1| 1
//rPUPC[15:0]
//| 0| 0| 1| 1| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0| 0
rPCONC=0x5f555555;
rPDATC=0xb1ff; //CS1 CS2是高电平选中
rPUPC =0x3000; //PULL UP RESISTOR should be enabled to I/O
//PORT D GROUP //所有输出输入要动态地设
//rPCOND[15..0]
//| BIT7 |.........................|BIT0
//|PD7|PD6|PD5|PD4|PD3|PD2|PD1|PD0
//| 01| 01| 01| 01| 01| 01| 01| 01 //???????????????????????????????00-input,01-output
//rPUPD[7:0]
//| 1| 1| 1| 1| 1| 1| 1| 1 //0-要上拉电阻 1-不要
rPDATD=0xff;
rPCOND=0x5555;
rPUPD =0xff; //数据是双向 不要上拉电阻
//These pins must be set only after CPU's internal LCD controller is enable
//PORT E GROUP
//rPCONE[8..0]
//| BIT8 |PE7 |PE6 |PE5 |PE4 |PE3..........|BIT0
//|ENDIAN|KIN3|KIN2|KIN1|KIN0|SLAV CLK|RXD0|TXD0| DIP SW
//| 00| 00 | 00 | 00| 00 | 00 | 10| 10| 00 //00-input
//|rPUPE[7:0]
// ?| 1 | 1 | 1| 1 | 1 | 1| 1| 1
//rPDATE=0x0;
rPCONE=0x00028; //All IO is INPUT
rPUPE =0xff; //PE8 do not have programmable pull-up resistor.
//PORT F GROUP
//rPCONF[21..0]
//| BIT8|..................................|BIT0
//|KO3|KO2|KO1|KO0|IMACLK|VSYNC|P SEN|SDA|SCL
//|001|001|001|001| 00 | 01 | 00 | 10| 10
//rPUPF[8:0]
//| 0| 0| 0| 0 | 1 | 1 | 1 | 1| 1
rPDATF=0x1ff; //KO0-KO3是输出
rPCONF=0x09244a;
rPUPF =0x1f;
//PORT G GROUP
//rPCONG[15..0]
//|BIT7|................................| BIT0
//| GPG7|GPG6|GPG5|GPG4|GPG3|WIEGAND-|WIEGAND+|EXINT0
//| 01| 01| 01| 01| 01| 01 | 01 | 11
//rPUPG[8:0]
//| 0| 0| 0| 0| 0| 1 | 1 | 1
rPDATG=0xff;
rPCONG=0x5557;
rPUPG =0x7; //should be enabled
rSPUCR=0x7; //D15-D0 pull-up disable
//| EXINT7|EXINT6|EXINT5|EXINT4|EXINT3|EXINT2|EXINT1|EXINT0
//| 000| 000| 000| 000| 000| 000| 000| 000
//000-low 001-high 01x-falling 10x-rising 11x-both edge
rEXTINT=0x0; //All EXTINT0-7 Low level interrupt
//Define the Non_Cache area
rNCACHBE0=(((Non_Cache_End)>>12)<<16)|((Non_Cache_Start)>>12);
}
//******************************************************************************
//******************************************************************************
void Uart_Init(int mclk,int baud)
{
int i;
if(mclk==0)
mclk=MCLK;
rUFCON0=(2<<6)|(1<<4)|(6)|1;
//FIFO trigger:tx/rx:8byte,tx/rx_fifo reset(will be cleared),FIFO enable.
rUFCON1=(2<<6)|(1<<4)|(6)|1;
rUMCON0=0x0; //modem control
rUMCON1=0x0;
//UART0
rULCON0=0x3; //Normal,No parity,1 stop,8 bit
//rUCON0=0x245; //tx=level int,rx=edge int,disable timeout int,enable rx error int,normal,interrupt or polling
rUCON0=0x245|0x80; //tx:level,rx:edge,tx/rx:int,rcv_time_out enabled,error int enable
rUBRDIV0=( (int)(mclk/16./baud + 0.5) -1 );
//UART1
rULCON1=0x3;
rUCON1=0x245;
rUBRDIV1=( (int)(mclk/16./baud + 0.5) -1 );
pISR_URXD0=(unsigned)Uart0_RxFifoInt;
//rINTMSK=~(BIT_GLOBAL|BIT_URXD0);
for(i=0;i<100;i++);
}
void __irq Uart0_RxFifoInt(void)
{ int i;
rI_ISPC=BIT_URXD0;
while( (rUFSTAT0&0xf) >0 ) //until FIFO is empty
{
i = rURXH0;
}
}
//*****************************************************************************
char whichUart=0;
void Uart_Select(U8 ch)
{
whichUart=ch;
}
//*****************************************************************************
void Uart_TxEmpty(U8 ch)
{
if(ch==0)
while(!(rUTRSTAT0 & 0x4)); //wait until tx shifter is empty.
else
while(!(rUTRSTAT1 & 0x4)); //wait until tx shifter is empty.
}
//*****************************************************************************
int UartRxStat(U8 ch)
{
if(!ch)
return (rUTRSTAT0&0x1);
else
return (rUTRSTAT1&0x1);
}
//******************************************************************************
//******************************************************************************
char Uart_Getch(U8 ch)
{
if(ch==0)
{
while(!(rUTRSTAT0 & 0x1)); //Receive data read
return RdURXH0();
}
else
{
while(!(rUTRSTAT1 & 0x1)); //Receive data ready
return rURXH1;
}
}
//******************************************************************************
//******************************************************************************
void Uart_SendByte(U8 ch, U8 data )
{
if(ch==0)
{
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);
}
else
{
if(data=='\n')
{
while(!(rUTRSTAT1 & 0x2));
Delay(10); //because the slow response of hyper_terminal
rUTXH1='\r';
}
while(!(rUTRSTAT1 & 0x2)); //Wait until THR is empty.
Delay(10);
rUTXH1=data;
}
}
//*****************************************************************************
void Uart_SendString(U8 ch,char *pt)
{
while(*pt)
Uart_SendByte(ch,*pt++);
}
//******************************************************************************
//******************************************************************************
//if you don't use vsprintf(), the code size is reduced very much.
void Uart_Printf(char *fmt,...)
{
va_list ap;
char string[256];
va_start(ap,fmt);
vsprintf(string,fmt,ap);
Uart_SendString(whichUart,string);
va_end(ap);
}
/**************************send_string to computer****************************/
void send_cpu_serial_string(U8 *str,U16 strlen)
{
U16 k=0;
do
{ //send_cpu_serial_char(*(str+k));
if (whichUart)
{ while(!(rUTRSTAT1 & 0x2)); //Wait until THR is empty.
Delay(10);
WrUTXH1(*(str+k));
}
else
{ while(!(rUTRSTAT0 & 0x2)); //Wait until THR is empty.
Delay(10);
WrUTXH0(*(str+k));
}
k++;
} while(k < strlen);
}
//*****************************************************************************
void Led_Display(int data)
{
rPDATB=(rPDATB & (~(1<<7)) ) | ((data & 0x1)<<7);
}
//******************************************************************************
//【功能说明】蜂鸣器鸣叫time个100us
//******************************************************************************
void Beep(unsigned int time)
{
rPDATB = (rPDATB | (1<<4)); //rPDATB:4 high-beep
Delay(time); //延时若干个100us
rPDATB = (rPDATB & (~(1<<4)));
}
void Beep_On(void)
{
rPDATB = (rPDATB | (1<<4)); //rPDATB:4 high-beep
}
void Beep_Off(void)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -