?? hd61202.c
字號(hào):
//關(guān)于12864的程序(ATMage64/HD61202)
//作者:eryong
//時(shí)間:2006-12-15
//主程序:
/************************************************************
LCD采用HD61202,192x64
控制單片機(jī)ATMage64 8MHz
************************************************************/
#include <iom64v.h>
#include <macros.h>
//#include <delay.h>
#include <stdio.h>
#include <D:\DISP\Hz.h>
#define BIT(x) (1 << (x))
/*LCD引腳定義 PA0-7對(duì)應(yīng)LCD DB0-DB7*/
#define CS1 0
#define CS2 1
#define CS3 2
#define E 3
#define RW 4
#define RS 5
#define LCD_LIGHT 6
//===================
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)
{
PORTC&=~BIT(CS1);
PORTC|=BIT(CS2);
LCD_NOP();
PORTC&=~BIT(RS);
PORTC|=BIT(E);
LCD_NOP();
PORTC&=~BIT(RW);
PORTA=x;
PORTC|=BIT(E);
PORTC&=~BIT(E);
PORTC|=BIT(CS1);
PORTC|=BIT(CS2);
}
//===================
//LCD左半屏寫數(shù)據(jù)
//===================
void LCD_Write_DatL(unsigned char x)
{
PORTC&=~BIT(CS1);
PORTC|=BIT(CS2);
LCD_NOP();
PORTC&=~BIT(RS);
PORTC|=BIT(E);
LCD_NOP();
PORTC|=BIT(RS);
PORTC&=~BIT(RW);
PORTA=x;
PORTC|=BIT(E);
PORTC&=~BIT(E);
PORTC|=BIT(CS1);
PORTC|=BIT(CS2);
}
//===================
//LCD右半屏寫命令字
//===================
void LCD_Write_ComR(unsigned char x)
{
PORTC|=BIT(CS1);
PORTC&=~BIT(CS2);
LCD_NOP();
PORTC&=~BIT(RS);
PORTC|=BIT(E);
LCD_NOP();
PORTC&=~BIT(RW);
PORTA=x;
PORTC|=BIT(E);
PORTC&=~BIT(E);
PORTC|=BIT(CS1);
PORTC|=BIT(CS2);
}
//===================
//LCD右半屏寫數(shù)據(jù)
//===================
void LCD_Write_DatR(unsigned char x)
{
PORTC|=BIT(CS1);
PORTC&=~BIT(CS2);
LCD_NOP();
PORTC&=~BIT(RS);
PORTC|=BIT(E);
LCD_NOP();
PORTC|=BIT(RS);
PORTC&=~BIT(RW);
PORTA=x;
PORTC|=BIT(E);
PORTC&=~BIT(E);
PORTC|=BIT(CS1);
PORTC|=BIT(CS2);
}
//LCD初始化
void LCD_Init(void)
{
LCD_Write_ComL(0x3e); LCD_Write_ComR(0x3e); //關(guān)閉顯示器
LCD_Write_ComL(0x3f); LCD_Write_ComR(0x3f); //打開顯示器
LCD_Write_ComL(0xc0); LCD_Write_ComR(0xc0); //設(shè)置左右半屏起始行,從0行開始
}
//LCD清屏
void LCD_Clr(void)
{
unsigned char i,j;
for(j=0;j<8;j++)
{
LCD_Write_ComL(0xb8|j); //左半屏頁設(shè)置指令
LCD_Write_ComL(0x40); //左半屏列地址設(shè)置指令
LCD_Write_ComR(0xb8|j); //右半屏頁設(shè)置指令
LCD_Write_ComR(0x40); //右半屏列地址設(shè)置指令
for(i=0; i<64; i++)
{
LCD_Write_DatL(0x00); //左半屏寫0;
LCD_Write_DatR(0x00); //右半屏寫0;
}
}
}
//====================================================================
//功能: 顯示8x16字符,位置按8x8一個(gè)點(diǎn)來定
// x:行坐標(biāo)(x=(0--8)) y:列坐標(biāo)(y=0--15) chrx:顯示字符
//====================================================================
void 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); //行坐標(biāo)確定頁地址
LCD_Write_ComR(0x40|y<<3); //列坐標(biāo)確定列地址
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一個(gè)點(diǎn)來定
// x:行坐標(biāo)(0-3) y:列坐標(biāo)(0-15) chrx:顯示字符(字符在字庫中的索引)
//======================================================
void 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以字節(jié)計(jì)算,在右半屏顯示,y以字節(jié)單位
{
y=y-8;
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]);
}
}
}
//======================================================
//顯示128x64點(diǎn)陣圖型,位置按8x8一個(gè)點(diǎn)來定
// x:行坐標(biāo)(0-3) y:列坐標(biāo)(0-15) chrx:圖型索引值
//======================================================
void LCD_WrMap8x8(unsigned char x,unsigned char y,unsigned char chrx)
{
unsigned char i;
unsigned int chr_m;
chr_m=chrx;
chr_m=chr_m*64;
if(y>=8) //y以字節(jié)計(jì)算,在右半屏顯示,y以字節(jié)單位
{
y=y-8;
LCD_Write_ComR(0xb8|x); //確定顯示行位置
LCD_Write_ComR(0x40|y<<3); //確定顯示列位置
for(i=0;i<64;i++)
{
LCD_Write_DatR(Hzk[chr_m+i]);
}
}
else
{
LCD_Write_ComL(0xb8|x);
LCD_Write_ComL(0x40|y<<3);
for(i=0;i<64;i++)
{
LCD_Write_DatL(Hzk[chr_m+i]);
}
}
}
//=============
//主程序
//=============
void main(void)
{
unsigned int i;
DDRA=0xff; PORTA=0x00; //數(shù)據(jù)端口輸出
DDRC=0xff; PORTC=0x04; //控制端口輸出
//#asm("wdr");
//#asm("SEI"); //開總中斷
Delay(200);
LCD_Init(); //LCD初始化
LCD_Clr(); //LCD清屏
Delay(200);
Delay(200);
for(i=0; i<8; i++)
{
LCD_WrMap8x8(i,0,2*i);
LCD_WrMap8x8(i,8,2*i+1);
}
//for(i=0;i<8;i++) LCD_WrCHr8x16(0,i,i); //第一行顯示8x16西文字符
//for(i=0;i<8;i++) LCD_WrCHr16x16(0,i*2,i);
//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中文字符
//for(i=0;i<8;i++) LCD_WrCHr16x16(6,i*2,i+24); //第四行顯示16x16中文字符
while(1)
{
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -