首页 > 代码库 > 00h
00h
C语言中的宏定义
//程序设计:傅越千
//2009.7.30
#include <c8051f360.h>
#include <stdio.h>
#include <absacc.h>
#define WDATADDR XBYTE[0XC009] //LCD写数据地址
#define RDATADDR XBYTE[0XC00B] //LCD读数据地址
#define WCOMADDR XBYTE[0XC008] //LCD写命令地址
#define RCOMADDR XBYTE[0XC00A] //LCD读命令地址
#define KEYCS XBYTE[0XC00C] //键盘片选地址
sbit LCD_RST=P3^0;
sbit START=P3^2;
unsigned char code CHINESE1[]={"高速数据采集系统"};
unsigned char code SINTAB[]={\
0x7f,0x82,0x85,0x88,0x8b,0x8f,0x92,0x95,0x98,0x9b,0x9e,0xa1,0xa4,0xa7,0xaa,0xad,\
0xb0,0xb3,0xb6,0xb8,0xbb,0xbe,0xc1,0xc3,0xc6,0xc8,0xcb,0xcd,0xd0,0xd2,0xd5,0xd7,\
0xd9,0xdb,0xdd,0xe0,0xe2,0xe4,0xe5,0xe7,0xe9,0xeb,0xec,0xee,0xef,0xf1,0xf2,0xf4,\
0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfb,0xfc,0xfd,0xfd,0xfe,0xfe,0xfe,0xfe,0xfe,\
0xff,0xfe,0xfe,0xfe,0xfe,0xfe,0xfd,0xfd,0xfc,0xfb,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,\
0xf5,0xf4,0xf2,0xf1,0xef,0xee,0xec,0xeb,0xe9,0xe7,0xe5,0xe4,0xe2,0xe0,0xdd,0xdb,\
0xd9,0xd7,0xd5,0xd2,0xd0,0xcd,0xcb,0xc8,0xc6,0xc3,0xc1,0xbe,0xbb,0xb8,0xb6,0xb3,\
0xb0,0xad,0xaa,0xa7,0xa4,0xa1,0x9e,0x9b,0x98,0x95,0x92,0x8f,0x8b,0x88,0x85,0x82,\
0x7f,0x7c,0x79,0x76,0x73,0x6f,0x6c,0x69,0x66,0x63,0x60,0x5d,0x5a,0x57,0x54,0x51,\
0x4e,0x4b,0x48,0x46,0x43,0x40,0x3d,0x3b,0x38,0x36,0x33,0x31,0x2e,0x2c,0x29,0x27,\
0x25,0x23,0x21,0x1e,0x1c,0x1a,0x19,0x17,0x15,0x13,0x12,0x10,0x0f,0x0d,0x0c,0x0a,\
0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x03,0x02,0x01,0x01,0x00,0x00,0x00,0x00,0x00,\
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x05,0x06,0x07,0x08,\
0x09,0x0a,0x0c,0x0d,0x0f,0x10,0x12,0x13,0x15,0x17,0x19,0x1a,0x1c,0x1e,0x21,0x23,\
0x25,0x27,0x29,0x2c,0x2e,0x31,0x33,0x36,0x38,0x3b,0x3d,0x40,0x43,0x46,0x48,0x4b,\
0x4e,0x51,0x54,0x57,0x5a,0x5d,0x60,0x63,0x66,0x69,0x6c,0x6f,0x73,0x76,0x79,0x7c} ;
unsigned char key_num=0xff; //存键号
unsigned char idata disp[128];
unsigned char flag=0;
void OSC_INIT (void)
{
SFRPAGE=0X0F;
OSCICL=OSCICL+4;
OSCICN=0XC2;
CLKSEL=0X30;
SFRPAGE=0;
}
//********************************************
void IO_INIT(void)
{
SFRPAGE=0X0F;
P0MDIN=0Xe7;
P0MDOUT=0X83;
P0SKIP=0XF9;
P1MDIN=0XFF;
P1MDOUT=0XFF;
P1SKIP=0XFF;
P2MDIN=0XFE;
P2MDOUT=0XFF;
P2SKIP=0XFF;
P3MDIN=0XFF;
P3MDOUT=0XFB; //FF*********
P3SKIP=0XFD;
P4MDOUT=0XFF;
XBR0=0X09;
XBR1=0X40; //禁止弱上拉,允许交叉开关 *****
SFRPAGE=0X0;
}
//********************************************
void XRAM_INIT(void)
{
SFRPAGE=0X0F;
EMI0CF=0X07;
SFRPAGE=0;
}
//********************************************
void SMB_INIT(void)
{
SMB0CF=0XC1;
}
//********************************************
void UART_INIT(void)
{
SCON0=0X0;
}
//********************************************
void DAC_INIT(void)
{
IDA0CN=0XF2;
}
//********************************************
void ADC_INIT(void)
{
REF0CN=0; //VDD为基准
AMX0P=0X08; //正端接P20
AMX0N=0X1F; //负端接GND
ADC0CF=0X2C; //左对齐,转换时钟2MHZ
ADC0CN=0X80; //写ADOBUSY启动AD
}
//********************************************
void INT0_INIT(void)
{
IT01CF=0X65; //选择P0.6为INT1,P0.5为INT0
IT0=1; //下降沿触发
IT1=1;
}
//********************************************
void TIMER_INIT(void)
{
TMOD=0x11; //T0、T1方式1
CKCON=0; //系统时钟12分频
TL0=0X78;
TH0=0XEC; //10MS
TL1=0X0C;
TH1=0XFE; //0.5MS
TMR2CN=0X04; //16位自动重装
TMR2RLL=0XF0; //10MS
TMR2RLH=0XD8;
TMR3CN=0X0C; //双8位自动重装入,系统时钟1/12
TMR3RLL=0XE0; //定时100us
TMR3RLH=0XFF;
TR0=1;
TR1=1;
}
//***********************************************
void PCA_INIT(void)
{
PCA0CN=0X40; //允许PCA计数器、定时器
PCA0MD=0; //禁止看门狗定时器
}
//***********************************************
void INT_INIT(void)
{
EX0=1; //INIT0,键盘
PX0=0; //INT0为低优先级
ET0=0; //T0
ET1=0; //T1
ET2=0; //T2
EIE1=0X0; //0X08,允许ADC中断
ES0=0; //uart
EA=1;
}
//**************************************************
void Init_device(void)
{
OSC_INIT();
IO_INIT();
XRAM_INIT();
SMB_INIT();
UART_INIT();
// DAC_INIT();
// ADC_INIT();
TIMER_INIT();
PCA_INIT();
INT0_INIT();
INT_INIT();
}
//**************************************************
//--------------------------------------------------------
void LCD_REST(void)
{
int i;
LCD_RST=0;
for(i=0;i<255;i++);
LCD_RST=1;
}
//********************************************************
void LCD_WC(unsigned char command) //LCD写命令
{
while(RCOMADDR&0X80);
WCOMADDR=command;
}
//********************************************************
void LCD_INIT(void) //LCD初始化
{
LCD_WC(0X30); //设为基本命令集
LCD_WC(0X01);
LCD_WC(0X02); //将DDRAM填满20H,并设定DDRAM地址计数器为0
LCD_WC(0X0C); //开整体显示
}
//***********************************************************
void LCD_WD(unsigned char d) //LCD写数据
{
while(RCOMADDR&0X80);
WDATADDR=d;
}
//**********************************************************
void LCD_HZ(unsigned char x,unsigned char temp[]) //显示一行字符
{
int i=0;
LCD_WC(x); //x代表位置,=0x80对应左上角
while(temp[i]!=0)
{
LCD_WD(temp[i]);
i++;
}
}
//********************************************************
void LCD_BYTE(unsigned char x,unsigned char temp) //显示一行字符
{
LCD_WC(x); //x代表位置,=0x80对应左上角
LCD_WD(temp);
}
//*********************************************************
void LCD_CLR(void) //LCD清屏
{
LCD_WC(0X01);
}
//*********************************************************
void INIT_XSRAM(void) //ROM中的SIN模拟数据复制到disp
{
int i,j;
for(i=0,j=0 ;i<128;i++){
disp[i]=SINTAB[j];
j=j+2;
}
}
//********************************************************
void CLRGDRAM(void) //清LCD VRAM
{
int i,j;
for(i=0;i<32;i++){
LCD_WC((i|0x80));
LCD_WC(0X80);
for(j=0;j<16;j++) LCD_WD(0x0);
}
for(i=0;i<32;i++){
LCD_WC((i|0x80));
LCD_WC(0X88);
for(j=0;j<16;j++) LCD_WD(0x00);
}
}
//********************************************************
void WR_GDRAM(void) //将disp[]数据送LCD显示
{
unsigned char buf[16];
unsigned char code tab[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
int i,j,k;
for(k=0;k<0x40;k++){
for(i=0;i<16;i++) buf[i]=0;
for(i=0,j=0;i<128;i++){
if(((~disp[i])>>2)==k){
buf[i/8]=buf[i/8]|tab[i%8];
}
}
if(k<32) {LCD_WC(k|0x80);LCD_WC(0X80);}
else {LCD_WC((k-0x20)|0x80);LCD_WC(0X88);}
for(i=0;i<16;i++) LCD_WD(buf[i]);
}
}
//********************************************************
void KEY_INIT0(void) interrupt 0
{
key_num=KEYCS&0x0f;
}
//********************************************************
void GET_DATA(void) interrupt 2 //取FPGA的采样数据
{
unsigned char xdata *p;
int i;
p=0x4000; //双口RAM的首地址
for(i=0;i<128;i++,p++) disp[i]=*p;
flag=1; //设置标志
}
main()
{
int i;
Init_device();
LCD_REST();
LCD_INIT();
LCD_HZ(0x90,CHINESE1);
LCD_INIT();
LCD_WC(0X34);
CLRGDRAM(); //清LCD
INIT_XSRAM();
WR_GDRAM(); //显示正弦
LCD_WC(0X36);
LCD_WC(0X30);
IE1=0;
EX1=1;
while(1)
{
if(flag) {
flag=0;
LCD_INIT();
LCD_WC(0X34);
CLRGDRAM(); //清LCD
WR_GDRAM(); //显示正弦
LCD_WC(0X36);
LCD_WC(0X30);
}
if((key_num&0xf0)==0)
{
switch(key_num)
{
case 0:
START=0;
for(i=0;i<20000;i++);
START=1;
break;
case 1: break;
}
key_num=0xff;
}
}
}
来自为知笔记(Wiz)
附件列表
- 11.png
00h
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。