📄 main.c
字号:
#include <stdio.h>
//#include <reg51.h>
#include <absacc.h>
#include <intrins.h>
#include "me.h"
#include "hzK.h"
sbit WATCHDOG = P1^1;//0xB5; //T1
sbit RUNLED = P1^0; //T0
/***************一个10ms延时程序************************/
void delay10ms(unsigned int time)
{
unsigned int i;
unsigned int j;
for (i=0;i<time;i++)
for(j=0;j<1746;j++);
}
//sbit spk=P1^7;
#define cmd_reset 0x0a4
#define cmd_test 0x0bf
#define decode0 0x80
#define decode1 0x0c8
#define cmd_read 0x15
#define undecode 0x90
#define rtl_cycle 0x0a3
#define rtr_cycle 0x0a2
#define rtl_uncyl 0x0a1
#define rtr_uncyl 0x0a0
#define actctl 0x98
#define segon 0x0e0
#define segoff 0x0c0
#define blinkctl 0x88
/*
文章编号:909----加入日期:2003-12-5
『关闭窗口』
CVAVR写的关于12864的程序(ATMage8L/HD61202)(huxiangming)
主程序:
*/
/************************************************************
LCD采用HD61202,128x64
控制单片机ATMage8L 8MHz
2003.12.5 huxiangming.
************************************************************/
//#include <mega8.h>
//#include <delay.h>
//#include <stdio.h>
//#include "hz.h"
/*LCD引脚定义 PB0-7对应LCD DB0-DB7*/
sbit DI =P2^0; // 数据\指令 选择 DI
sbit RW =P2^1; // 读\写 选择
sbit E =P2^2; // 读\写使能
sbit CS1 =P2^3; // 片选1,低有效(前64列)
sbit CS2 =P2^4; // 片选2,低有效(后64列)
sbit RST=P2^5; // 复位
void LCD_NOP(void)
{
unsigned char i;
for(i=0;i<50;i++);
}
void Delay(int x)
{
int i,j;
for(j=0;j<x;j++)
{
for(i=0;i<250;i++);
}
}
//LCD左半屏写命令字
void LCD_Write_ComL(unsigned char x)
{
LCD_NOP();
CS1=1; CS2=0;
DI=0; //0=指令 1=数据
RW=0; //0=写 1=读
E=1;
P0=x;
LCD_NOP();
E=0;
}
//LCD左半屏写数据
void LCD_Write_DatL(unsigned char x)
{
LCD_NOP();
CS1=1;CS2=0;
DI=1; //0=指令 1=数据
RW=0; //0=写 1=读
E=1;
P0=x;
LCD_NOP();
E=0; //下降沿锁存数据
}
//LCD右半屏写命令字
void LCD_Write_ComR(unsigned char x)
{
LCD_NOP();
CS1=0;CS2=1;
DI=0; //0=指令 1=数据
RW=0; //0=写 1=读
E=1;
P0=x;
LCD_NOP();
E=0;
}
//LCD右半屏写数据
void LCD_Write_DatR(unsigned char x)
{
LCD_NOP();
CS1=0;CS2=1;
DI=1; //0=指令 1=数据
RW=0; //0=写 1=读
E=1;
P0=x;
LCD_NOP();
E=0; //下降沿锁存数据
}
//LCD左半屏读状态
unsigned char LCD_Read_StaL()
{
unsigned char x;
CS1=1;CS2=0;
DI=0; //0=指令 1=数据
RW=1; //0=写 1=读
E=1;
LCD_NOP();
x=P0;
E=0;
return x;
}
//LCD右半屏读状态
unsigned char LCD_Read_StaR()
{
unsigned char x;
CS1=0;CS2=1;
DI=0; //0=指令 1=数据
RW=1; //0=写 1=读
E=1;
LCD_NOP();
x=P0;
E=0;
return x;
}
//LCD清屏
void LCD_Clr(void)
{
unsigned char i,j;
for(j=0;j<8;j++)
{
LCD_Write_ComL(0xb8|j);
LCD_Write_ComL(0x40);
LCD_Write_ComR(0xb8|j);
LCD_Write_ComR(0x40);
for(i=0;i<64;i++)
{
LCD_Write_DatL(0x00);
LCD_Write_DatR(0x00);
}
}
}
//显示8x16字符,位置按8x8一个点来定 x:列坐标 y:行坐标 chrx:显示字符
LCD_WrCHr8x16(unsigned char x,unsigned char y,unsigned char chrx)
{
unsigned char i;
unsigned int chr_m;
chr_m=chrx;
chr_m=chr_m*16;
if(y>=8)
{
y=y-8;
LCD_Write_ComR(0xb8|x);
LCD_Write_ComR(0x40|y<<3);
for(i=0;i<8;i++)
{
LCD_Write_DatR(Ezk[chr_m+i]);
}
LCD_Write_ComR(0xb9|x);
LCD_Write_ComR(0x40|y<<3);
for(i=8;i<16;i++)
{
LCD_Write_DatR(Ezk[chr_m+i]);
}
}
else
{
LCD_Write_ComL(0xb8|x);
LCD_Write_ComL(0x40|y<<3);
for(i=0;i<8;i++)
{
LCD_Write_DatL(Ezk[chr_m+i]);
}
LCD_Write_ComL(0xb9|x);
LCD_Write_ComL(0x40|y<<3);
for(i=8;i<16;i++)
{
LCD_Write_DatL(Ezk[chr_m+i]);
}
}
}
//显示16x16字符,位置按8x8一个点来定 x:列坐标 y:行坐标 chrx:显示字符*/
LCD_WrCHr16x16(unsigned char x,unsigned char y,unsigned char chrx){
unsigned char i;
unsigned int chr_m;
chr_m=chrx;
chr_m=chr_m*32;
if(y>=8)
{
y=y-4;
LCD_Write_ComR(0xb8|x);
LCD_Write_ComR(0x40|y<<3);
for(i=0;i<8;i++)
{
LCD_Write_DatR(Hzk[chr_m+i]);
}
LCD_Write_ComR(0xb8|x);
LCD_Write_ComR(0x48|y<<3);
for(i=8;i<16;i++)
{
LCD_Write_DatR(Hzk[chr_m+i]);
}
LCD_Write_ComR(0xb9|x);
LCD_Write_ComR(0x40|y<<3);
for(i=16;i<24;i++)
{
LCD_Write_DatR(Hzk[chr_m+i]);
}
LCD_Write_ComR(0xb9|x);
LCD_Write_ComR(0x48|y<<3);
for(i=24;i<32;i++)
{
LCD_Write_DatR(Hzk[chr_m+i]);
}
}
else
{
LCD_Write_ComL(0xb8|x);
LCD_Write_ComL(0x40|y<<3);
for(i=0;i<8;i++)
{
LCD_Write_DatL(Hzk[chr_m+i]);
}
LCD_Write_ComL(0xb8|x);
LCD_Write_ComL(0x48|y<<3);
for(i=8;i<16;i++)
{
LCD_Write_DatL(Hzk[chr_m+i]);
}
LCD_Write_ComL(0xb9|x);
LCD_Write_ComL(0x40|y<<3);
for(i=16;i<24;i++)
{
LCD_Write_DatL(Hzk[chr_m+i]);
}
LCD_Write_ComL(0xb9|x);
LCD_Write_ComL(0x48|y<<3);
for(i=24;i<32;i++)
{
LCD_Write_DatL(Hzk[chr_m+i]);
}
}
}
/*******************************************************************/
// 绘制一幅图片
//位置按由点来定 x:列坐标 y:行坐标 *gImage:显示图片*/
/*******************************************************************/
void Wr_pic(unsigned char x,unsigned char y,unsigned char *gImage)
{
unsigned char i,j;
for(i=0;i<64;i++)
{
for(j=0;j<16;j++)
{
// LCD12864_command(0x34);
// LCD12864_command(Y);
// LCD12864_command(X);
// LCD12864_data(*(gImage+i*16+j)); // low 8 bits
// LCD12864_data(*(gImage+i*16+j+1)); // high 8 bits
// LCD12864_command(0x36);
x++;
j++;
}
y++;
if(y>0x9f)
y=0x80;
x=0x80+((i+1)/32)*8;
}
// LCD12864_command(0x30);
}
//LCD初始化
void LCD_Init(void)
{
//unsigned char temp,temp1;
LCD_Write_ComL(0x3e);
LCD_Write_ComR(0x3e);
Delay(10);
LCD_Write_ComL(0x3f);
LCD_Write_ComR(0x3f);
Delay(10);
LCD_Write_ComL(0xc0);
//LCD_Write_ComR(0xc0);
Delay(10);
}
//主程序
void main(void)
{
unsigned int i;
RUNLED=0;
RST=0;
Delay(10);
RST=1;
LCD_Init(); //LCD初始化
RUNLED=~RUNLED;
while(1){
LCD_Clr(); //LCD清屏
for(i=0;i<16;i++) LCD_WrCHr8x16(0,i,i); //第一行显示8x16西文字符
// for(i=0;i<8;i++) LCD_WrCHr16x16(0,i*2,i); //第二行显示16x16中文字符
// for(i=0;i<8;i++) LCD_WrCHr16x16(2,i*2,i+8); //第二行显示16x16中文字符
// for(i=0;i<8;i++) LCD_WrCHr16x16(4,i*2,i+16); //第三行显示16x16中文字符
// for(i=0;i<8;i++) LCD_WrCHr16x16(6,i*2,i+24); //第四行显示16x16中文字符
RUNLED=~RUNLED;
delay10ms(100);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -