📄 main.c
字号:
/*********************************************************
Name: Main.c
Function: AD7892 定时采集与LCD波形显示程序
Note: 读取A/D转换结果时不能使用启动地址
否则会在读取结果时又再次启动ADC
Date: May 22, 2006
**********************************************************/
#include <string.h>
#include "Def.h"
#include "Option.h"
#include "2410addr.h"
#include "2410lib.h"
#include "2410slib.h"
#include "ascii.h"
#include "chinesefont.h"
//16-bpp colors pre-definition
#define BLACK 0x0
#define WHITE 0xffff
#define RED 0xf800
#define GREEN 0x7e0
#define BLUE 0x1f
#define YELLOW ((RED)+(GREEN))
#define CYAN ((GREEN)+(BLUE))
#define PURPLE ((RED)+(BLUE))
#define GRAY ((16<<11)+(32<<5)+16)
#define SKYBLUE ((0<<11)+(32<<5)+31)
#define VIOLET ((16<<11)+(0<<5)+31)
#define ORANGE ((31<<11)+(32<<5)+0)
#define nY0 (*(volatile unsigned short*)0x08008000) //AD_CS
#define nY1 (*(volatile unsigned short*)0x08008800) //AD_CONVST
#define nY2 (*(volatile unsigned short*)0x08009000)
#define nY3 (*(volatile unsigned short*)0x08009800)
#define nY4 (*(volatile unsigned short*)0x0800a000)
#define nY5 (*(volatile unsigned short*)0x0800a800)
#define nY6 (*(volatile unsigned short*)0x0800b000)
#define SAMP_NUM (1024)
#define XSCALE (5) //(Full-scale range = 4096)>>5=128, display area in rectangle(20, 0, 160, 319)
#define YSCALE (SAMP_NUM/320)
#define SAMP_RATE_1KHZ (1)
#define SAMP_RATE_2KHZ (2)
#define SAMP_RATE_5KHZ (5)
#define SAMP_RATE_10KHZ (10)
#define SAMP_RATE_20KHZ (20)
#define SAMP_RATE_50KHZ (50)
#define SAMP_RATE_100KHZ (100)
#define SAMP_RATE_200KHZ (200)
volatile S16 result[SAMP_NUM];
static U32 ADC_Index;
static int samplingrate=0;
volatile char Conversion_Complete;
int save_B,save_G,save_H,save_PB,save_PG,save_PH,save_MI;
unsigned save_rGPCUP,save_rGPCDAT,save_rGPCCON;
unsigned save_rGPDUP,save_rGPDDAT,save_rGPDCON;
static void __irq Eint1Int(void)
{
ClearPending(BIT_EINT1);
/*rSRCPND |= BIT_EINT1;
rINTPND |= BIT_EINT1;
rINTPND = rINTPND;*/
result[ADC_Index] = nY0;
ADC_Index++;
if (ADC_Index>=SAMP_NUM)
{
Conversion_Complete = 1;
rINTMSK |= BIT_EINT1 ; //disable ADC interrupt
}
}
static void __irq Timer0Done(void)
{
ClearPending(BIT_TIMER0);
/*rSRCPND |= BIT_TIMER0;
rINTPND |= BIT_TIMER0;
rINTPND = rINTPND;*/
nY1 = 0; //start ADC, note address!
}
void Timer_Port_Init(void)
{
save_B = rGPBCON;
save_G = rGPGCON;
save_H = rGPHCON;
save_PB = rGPBUP;
save_PG = rGPGUP;
save_PH = rGPHUP;
save_MI = rMISCCR;
rGPBUP = rGPBUP & ~(0x1f) | 0x1f; //GPB4 ~ 0
rGPBCON = rGPBCON & ~(0x3ff) | 0x2aa; //Function Setting TCLK0, TOUT3 ~ 0
rGPGUP = rGPGUP & ~(0x800) | 0x800; //GPG11
rGPGCON = rGPGCON & ~(0xc00000) | 0xc00000; //TCLK1
rGPHUP = rGPHUP & ~(0x200) | 0x200; //GPH9
rGPHCON = rGPHCON & ~(0x3<<18) | (0x2<<18); //CLKOUT0
rMISCCR = rMISCCR & ~(0xf0) | 0x40; //Select PCLK with CLKOUT0
}
void Timer_Port_Return(void)
{
rGPBCON = save_B;
rGPGCON = save_G;
rGPHCON = save_H;
rGPBUP = save_PB;
rGPGUP = save_PG;
rGPHUP = save_PH;
rMISCCR = save_MI;
}
void Lcd_Port_Init(void)
{
save_rGPCCON=rGPCCON;
save_rGPCDAT=rGPCDAT;
save_rGPCUP=rGPCUP;
save_rGPDCON=rGPDCON;
save_rGPDDAT=rGPDDAT;
save_rGPDUP=rGPDUP;
rGPCUP=0xffffffff; // Disable Pull-up register
rGPCCON=0xaaaaaaaa; //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND
rGPDUP=0xffffffff; // Disable Pull-up register
rGPDCON=0xaaaaaaaa; //Initialize VD[23:8]
//Uart_Printf("Initializing GPIO ports......\n");
}
void Lcd_Port_Return(void)
{
rGPCCON=save_rGPCCON;
rGPCDAT=save_rGPCDAT;
rGPCUP=save_rGPCUP;
rGPDCON=save_rGPDCON;
rGPDDAT=save_rGPDDAT;
rGPDUP=save_rGPDUP;
}
U32 (* frameBuffer)[120];
void Lcd_Init(void)
{
frameBuffer=(U32 (*)[120])0x33800000;
rLCDCON1=(6<<8)|(0<<7)|(3<<5)|(12<<1)|0;
// TFT LCD panel,16bpp TFT,ENVID=off
rLCDCON2=(1<<24)|(319<<14)|(2<<6)|(1);
rLCDCON3=(6<<19)|(239<<8)|(2);
rLCDCON4=(13<<8)|(95);
rLCDCON5=(1<<11)|(1<<9)|(1<<8); //FRM5:6:5,HSYNC and VSYNC are inverted
rLCDSADDR1=(((U32)frameBuffer>>22)<<21)|(((U32)frameBuffer>>1)& 0x1fffff);
rLCDSADDR2=( ((U32)frameBuffer+(240*320*16/8))>>1 )& 0x1fffff;
rLCDSADDR3=(0<<11)|(240);
rLCDINTMSK|=(3); // MASK LCD Sub Interrupt
rLPCSEL&=(~3); // Disable LPC3600
rTPAL=0; // Disable Temp Palette
}
void PutPixel(U32 x,U32 y,U32 c)
{
if(x<240 && y<320)
frameBuffer[(y)][(x)/2]=( frameBuffer[(y)][x/2]
& ~(0xffff0000>>((x)%2)*16) ) | ( (c&0x0000ffff)<<((2-1-((x)%2))*16) );
}
void ClearScreen(U16 c)
{
int i,j;
for(j=0;j<320;j++)
for(i=0;i<240;i++)
PutPixel(i,j,c);
}
void Draw_Line(U16 x1, U16 y1, U16 x2, U16 y2, U16 color)
{
int dx,dy,e;
dx=x2-x1;
dy=y2-y1;
if(dx>=0)
{
if(dy >= 0) // dy>=0
{
if(dx>=dy) // 1/8 octant
{
e=dy-dx/2;
while(x1<=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1+=1;e-=dx;}
x1+=1;
e+=dy;
}
}
else // 2/8 octant
{
e=dx-dy/2;
while(y1<=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1+=1;e-=dy;}
y1+=1;
e+=dx;
}
}
}
else // dy<0
{
dy=-dy; // dy=abs(dy)
if(dx>=dy) // 8/8 octant
{
e=dy-dx/2;
while(x1<=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1-=1;e-=dx;}
x1+=1;
e+=dy;
}
}
else // 7/8 octant
{
e=dx-dy/2;
while(y1>=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1+=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
else //dx<0
{
dx=-dx; //dx=abs(dx)
if(dy >= 0) // dy>=0
{
if(dx>=dy) // 4/8 octant
{
e=dy-dx/2;
while(x1>=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1+=1;e-=dx;}
x1-=1;
e+=dy;
}
}
else // 3/8 octant
{
e=dx-dy/2;
while(y1<=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1+=1;
e+=dx;
}
}
}
else // dy<0
{
dy=-dy; // dy=abs(dy)
if(dx>=dy) // 5/8 octant
{
e=dy-dx/2;
while(x1>=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1-=1;e-=dx;}
x1-=1;
e+=dy;
}
}
else // 6/8 octant
{
e=dx-dy/2;
while(y1>=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1-=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
}
void Draw_Rectangle(U16 x1, U16 y1, U16 x2, U16 y2, U16 color)
{
Draw_Line(x1, y1, x2, y1, color);
Draw_Line(x2, y1, x2, y2, color);
Draw_Line(x1, y2, x2, y2, color);
Draw_Line(x1, y1, x1, y2, color);
}
void Fill_Rectangle(U16 x1, U16 y1, U16 x2, U16 y2, U16 color)
{
U16 i;
for(i=y1; i<=y2; i++)
{
Draw_Line(x1, i, x2, i, color);
}
}
void Display_Ascii_Clockwise90(char *s, U16 x, U16 y, U16 color)
{
U16 i, j;
unsigned long location;
U8 buffer[16];
while(*s)
{
location=(*s)*16L;
memcpy(buffer, &ascii16x8[location], 16);
for(j=0; j<8; j++)
for(i=0; i<16; i++)
{
if((buffer[16-1-i]>>(7-j)) & 0x1)
PutPixel(x+i, y+j, color);
}
s+=1;
y+=8;
}
}
void Display_Chinese_Clockwise90(char *mat, U8 matsize, U16 x, U16 y, U16 color)
{
int i, j, k, n;
n = (matsize - 1) / 8 + 1;
for(i = 0; i < n; i++)
for(k = 0; k < 8; k++)
for(j = (matsize-1); j >= 0; j--)
{
if(mat[j*n + i] & (0x80 >> k))
PutPixel(x + (matsize-1-j), y + i*8 + k, color);
}
}
void Lcd_EnvidOnOff(int onoff)
{
if(onoff==1)
rLCDCON1|=1; // ENVID=ON
else
rLCDCON1&=0x3fffe; // ENVID Off
}
//===================Caculate the digit of an integer======================
U8 Digit_Integer(int num)
{
U8 digCount=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -