#include <stdarg.h>
#include <stdio.h>
#include <math.h>
#include <intrins.h>
#include <absacc.h>
#include <string.h>
#include <LCD_160128.h>
sbit RESET = P3^3;
#define ASC_CHR_WIDTH 8
#define ASC_CHR_HEIGHT 12
#define HZ_CHR_HEIGHT 12
#define HZ_CHR_WIDTH 12
uchar code LCD_WIDTH = 20;
uchar code LCD_HEIGHT= 128;
uchar code ASC_MSK[96*12]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
uchar gCurRow,gCurCol;
uchar tCurRow,tCurCol;
uchar ShowModeSW;
uint txthome,grhome;
uchar Status_BIT_01();
uchar Status_BIT_3();
uchar GetCol();
uchar GetRow();
uchar LCD_Write_Command(uchar cmd);
uchar LCD_Write_Command_P1(uchar cmd,uchar para1);
uchar LCD_Write_Command_P2(uchar cmd,uchar para1,uchar para2);
uchar LCD_Write_Data(uchar dat);
uchar LCD_Read_Data();
void cls();
uchar LCD_Initialise();
void Set_LCD_POS(uchar row,uchar col);
void charout(uchar *str);
uchar dprintf(uchar x,uchar y,uchar *fmt);
void OutToLCD(uchar Dat,uchar x,uchar y);
void Line(uchar x1,uchar y1,uchar x2,uchar y2,bit Mode);
void Pixel(uchar x,uchar y,bit Mode);
uchar Status_BIT_01()
{
uchar i;
for(i=5;i>0;i--)
{
if((LCMCW & 0x03)==0x03)
break;
}
return i;
}
uchar Status_BIT_3()
{
uchar i;
for(i=5;i>0;i--)
{
if((LCMCW & 0x08)==0x08)
break;
}
return i;
}
uchar LCD_Write_Command_P2(uchar cmd,uchar para1,uchar para2)
{
if(Status_BIT_01()==0) return 1;
LCMDW = para1;
if(Status_BIT_01()==0) return 2;
LCMDW = para2;
if(Status_BIT_01()==0) return 3;
LCMDW = cmd;
return 0;
}
uchar LCD_Write_Command_P1(uchar cmd,uchar para1)
{
if(Status_BIT_01()==0) return 1;
LCMDW = para1;
if(Status_BIT_01()==0) return 2;
LCMDW = cmd;
return 0;
}
uchar LCD_Write_Command(uchar cmd)
{
if(Status_BIT_01()==0) return 1;
LCMDW = cmd;
return 0;
}
uchar LCD_Write_Data(uchar dat)
{
if(Status_BIT_3()==0) return 1;
LCMDW = dat;
return 0;
}
uchar LCD_Read_Data()
{
if(Status_BIT_01()==0) return 1;
return LCMDW;
}
void Set_LCD_POS(uchar row,uchar col)
{
uint Pos;
Pos = row*LCD_WIDTH+col;
LCD_Write_Command_P2(LC_ADD_POS,Pos%256,Pos/256);
gCurRow = row;
gCurCol = col;
}
void cls()
{
uint i;
LCD_Write_Command_P2(LC_ADD_POS,0x00,0x00);
LCD_Write_Command(LC_AUT_WR);
for(i=0;i<0x2000;i++)
{
Status_BIT_3();
LCD_Write_Data(0x00);
}
LCD_Write_Command(LC_AUT_OVR);
LCD_Write_Command_P2(LC_ADD_POS,0x00,0x00);
gCurRow = 0;
gCurCol = 0;
}
uchar LCD_Initialise()
{
RESET = 0;
RESET = 1;
LCD_Write_Command_P2(LC_TXT_STP,0x00,0x00);
LCD_Write_Command_P2(LC_TXT_WID,LCD_WIDTH,0x00);
LCD_Write_Command_P2(LC_GRH_STP,0x00,0x00);
LCD_Write_Command_P2(LC_GRH_WID,LCD_WIDTH,0x00);
LCD_Write_Command_P1(LC_CGR_POS,CGRAMSTART >> 11);
LCD_Write_Command(LC_CUR_SHP | 0x01);
LCD_Write_Command(LC_MOD_OR);
LCD_Write_Command(LC_DIS_SW | 0x08);
grhome = GRSTART;
txthome = TXTSTART;
return 0;
}
uchar Display_Str_at_xy(uchar x,uchar y,uchar *fmt)
{
char c1,c2,cData;
uchar i=0,j,uLen;
uLen = strlen(fmt);
while(i<uLen)
{
c1 = fmt[i];
c2 = fmt[i+1];
Set_LCD_POS(y,x/8);
if(c1>=0)
{
if(c1<0x20)
{
switch(c1)
{
case CR:
case LF:
i++;
x=0;
if(y<112) y+=HZ_CHR_HEIGHT;
continue;
case BS:
i++;
if(y>ASC_CHR_WIDTH) y-=ASC_CHR_WIDTH;
cData=0x00;
break;
}
}
for(j=0;j<ASC_CHR_HEIGHT;j++)
{
if(c1>=0x1f)
{
cData = ASC_MSK[(c1-0x1f)*ASC_CHR_HEIGHT+j];
Set_LCD_POS(y+j,x/8);
if((x%8)==0)
{
LCD_Write_Command(LC_AUT_WR);
LCD_Write_Data(cData);
LCD_Write_Command(LC_AUT_OVR);
}
else
OutToLCD(cData,x,y+j);
}
Set_LCD_POS(y+j,x/8);
}
if(c1!=BS) x+=ASC_CHR_WIDTH;
}
i++;
}
return uLen;
}
void OutToLCD(uchar Dat,uchar x,uchar y)
{
uchar dat1,dat2,a,b;
b = x%8;
a = 8-b;
Set_LCD_POS(y,x/8);
LCD_Write_Command(LC_AUT_RD);
dat1 = LCD_Read_Data();
dat2 = LCD_Read_Data();
dat1 = (dat1 &(0xff<<a)) | (Dat>>b);
dat2 = (dat1 &(0xff>>b)) | (Dat<<a);
LCD_Write_Command(LC_AUT_OVR);
Set_LCD_POS(y,x/8);
LCD_Write_Command(LC_AUT_WR);
LCD_Write_Data(dat1);
LCD_Write_Data(dat2);
LCD_Write_Command(LC_AUT_OVR);
}
void Pixel(uchar x,uchar y,bit Mode)
{
uchar start_addr,dat;
start_addr=7-(x%8);
dat = LC_BIT_OP | start_addr;
if(Mode) dat |= 0x08;
Set_LCD_POS(y,x/8);
LCD_Write_Command(LC_BIT_OP | dat);
}
void Exchange(uchar *a,uchar *b)
{
uchar t;
t = *a;*a = *b;*b = t;
}
void Line(uchar x1,uchar y1,uchar x2,uchar y2,bit Mode)
{
uchar x,y;
float k,b;
if(abs(y1-y2)<=abs(x1-x2))
{
k=(float)(y1-y2)/(float)(x2-x1);
b=y1-k*x1;
if(x1>x2) Exchange(&x1,&x2);
for(x=x1;x<=x2;x++)
{
y=(uchar)(k*x+b);
Pixel(x,y,Mode);
}
}
else
{
k=(float)(x2-x1)/(float)(y2-y1);
b=x1-k*y1;
if(y1>y2) Exchange(&y1,&y2);
for(y=y1;y<=y2;y++)
{
x=(uchar)(k*y+b);
Pixel(x,y,Mode);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
《单片机C语言程序设计实训100例:基于8051+Proteus仿真》的源代码
共449个文件
hex:46个
lst:37个
obj:37个
4星 · 超过85%的资源 需积分: 9 48 下载量 163 浏览量
2010-03-20
13:43:36
上传
评论 4
收藏 1.18MB RAR 举报
温馨提示
《单片机C语言程序设计实训100例:基于8051+Proteus仿真》的源代码 这里只有基础部分和硬件应用的源代码,没有综合设计这部分的C语言的代码,希望对各位有用.
资源推荐
资源详情
资源评论
收起资源包目录
《单片机C语言程序设计实训100例:基于8051+Proteus仿真》的源代码 (449个子文件)
1 1KB
11 4KB
12 14KB
12864LCD图形滚动演示 31KB
13 11KB
14 26KB
15 40KB
16 4KB
160128LCD图形滚动演示 47KB
1602字符液晶滚动演示 13KB
17 13KB
18 9KB
19 3KB
2 1KB
20 3KB
21 2KB
22 2KB
23 13KB
24 11KB
24c04 7KB
24c04 7KB
24C04与数码管 2KB
25 11KB
26 2KB
27 3KB
28 3KB
2×20串行字符液晶演示 4KB
3 3KB
4 2KB
555定时器实验 621B
6264 2KB
6264扩展内存 2KB
74HC154译码器应用 592B
74HC595串入并出芯片应用 1KB
74LS138译码器应用 600B
74LS148扩展中断 733B
8 3KB
9 1KB
STARTUP.A51 6KB
STARTUP.A51 6KB
STARTUP.A51 6KB
STARTUP.A51 6KB
STARTUP.A51 6KB
STARTUP.A51 6KB
ADC0808 PWM实验 3KB
ADC0809模数转换与显示 3KB
ADC0832模数转换与显示 9KB
25_Uv2.Bak 0B
24_Uv2.Bak 0B
bcd 2KB
BCD译码数码管显示数字 2KB
24C04.bin 2B
160128LCD显示的图像.bmp 60KB
12864LCD显示的图像.bmp 24KB
LCD_160128.c 5KB
17.c 4KB
25.c 4KB
23.c 4KB
24.c 3KB
main.c 3KB
13.c 3KB
LCD_12864.c 2KB
main.c 2KB
18.c 2KB
24c04.c 2KB
24c04.c 2KB
LCD1602.c 1KB
main.c 1KB
27.c 1KB
16.c 966B
11.c 898B
20.c 852B
8.c 804B
19.c 792B
3.c 785B
26.c 739B
28.c 686B
22.c 627B
bcd.c 440B
21.c 381B
9.c 358B
4.c 349B
1.c 306B
2.c 294B
6264.c 287B
Last Loaded 用8255实现接口扩展.DBK 114KB
Last Loaded 24C04与数码管.DBK 105KB
Last Loaded PCF8591模数与数模转换实验.DBK 101KB
Last Loaded 74LS148扩展中断.DBK 100KB
Last Loaded ADC0809模数转换与显示.DBK 98KB
Last Loaded 1602字符液晶滚动演示程序.DBK 84KB
Last Loaded BCD译码数码管显示数字.DBK 84KB
Last Loaded 键控看门狗.DBK 81KB
Last Loaded 用DAC0832生成锯齿波.DBK 68KB
Last Loaded 555定时器实验.DBK 52KB
Backup Of ADC0809模数转换与显示.DBK 52KB
Last Loaded ADC0832模数转换与显示.DBK 46KB
Last Loaded 正反转可控的直流电机.DBK 45KB
Last Loaded MAX7221控制数码管动态显示.DBK 43KB
Last Loaded 74HC154译码器应用.DBK 43KB
共 449 条
- 1
- 2
- 3
- 4
- 5
资源评论
- zhxh07132014-07-13有点蒙人,一点都不全,应该上传全一点的资料啊
- yage19812014-11-14东西太少了,一点也不全
- wqychina2015-07-03还不错,就是只有源文件,代码注释不是很完整
xin_apple
- 粉丝: 2
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功