📄 12864h.txt
字号:
/*使用MCU: ATMEGA8535L
LCD MODULE: 128*64
IC Control:S6B0108
*/
#include <avr/io.h>
#include <inttypes.h>
//#include <stdlib.h>
#include <avr/delay.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#define pdout PORTC
#define pdin PINC
#define pcont PORTB
#define pcont1 PORTD
#define e PB0
#define rw PB1
#define rs PB2
#define cs1 PB3
#define cs2 PB4
#define rst PD6
#define set_Bit(val, bitn) (val |=(1<<(bitn))) //设置某一位
#define clr_Bit(val, bitn) (val&=~(1<<(bitn))) //清除某一位
#define get_Bit(val, bitn) (val &(1<<(bitn)) ) //取某一位
#define nop() asm("nop")
#define TC2_EN TIMSK |= (<<1OCIE2)|(1<<TOIE2) //启动TC2定时比较和溢出
#define TC2_DIS TIMSK &=~ (1<<OCIE2)|(1<<TOIE2)//禁止TC2再定时比较和溢出
#define uchar unsigned char //
#define uint unsigned int //
static uint g_aAdValue[8]; //A/D 转换缓冲
//static uchar g_datbuf[5];// 串口通讯数据缓冲区 接收存储空间
static uchar datbuf1=0;
static uchar datbuf2=0;
static uchar datbuf3=0;
static uchar datbuf4=0;
// uchar datbuf[5]={0,0,0,0,0,};
// static uchar g_aAdValue[5];
static uchar column;
static uchar row;
///static uint example;
//static uchar columnbuf;
//static uchar rowbuf;
static uchar cursor=0x5f;
static uchar autoscroll=0; //自动卷动标志
static uchar pwmbuf;
//=====================================================
const prog_uchar leddat[]= //
{
"0" /*0*/
"1"/*1*/
"2"/*2*/
"3"/*3*/
"4"/*4*/
"5"/*5*/
"6"/*6*/
"7"/*7*/
"8"/*8*/
"9"/*9*/
"A"/*A*/
"B"/*B*/
"C"/*C*/
"D"/*D*/
"E"/*E*/
"F"/*F*/
};
/////////////////8*8 dots/////////////////////////////////
const prog_uchar t5x8[]={
0x00,0x00,0x00,0x00,0x00, //" "=00H
0x00,0x00,0x4F,0x00,0x00, //"!"=01H
0x00,0x07,0x00,0x07,0x00, //" "=02H
0x14,0x7F,0x14,0x7F,0x14, //"#"=03H
0x24,0x2A,0x7F,0x2A,0x12, //"$"=04H
0x23,0x13,0x08,0x64,0x62, //"%"=05H
0x36,0x49,0x55,0x22,0x50, //"&"=06H
0x00,0x05,0x03,0x00,0x00, //"'"=07H
0x00,0x1C,0x22,0x41,0x00, //"("=08H
0x00,0x41,0x22,0x1C,0x00, //")"=09H
0x14,0x08,0x3E,0x08,0x14, //"*"=0AH
0x08,0x08,0x3E,0x08,0x08, //"+"=0BH
0x00,0x50,0x30,0x00,0x00, //";"=0CH
0x08,0x08,0x08,0x08,0x08, //"-"=0DH
0x00,0x60,0x60,0x00,0x00, //"."=0EH
0x20,0x10,0x08,0x04,0x02, //"/"=0FH
0x3E,0x51,0x49,0x45,0x3E, //"0"=10H
0x00,0x42,0x7F,0x40,0x00, //"1"=11H
0x42,0x61,0x51,0x49,0x46, //"2"=12H
0x21,0x41,0x45,0x4B,0x31, //"3"=13H
0x18,0x14,0x12,0x7F,0x10, //"4"=14H
0x27,0x45,0x45,0x45,0x39, //"5"=15H
0x3C,0x4A,0x49,0x49,0x30, //"6"=16H
0x01,0x01,0x79,0x05,0x03, //"7"=17H
0x36,0x49,0x49,0x49,0x36, //"8"=18H
0x06,0x49,0x49,0x29,0x1E, //"9"=19H
0x00,0x36,0x36,0x00,0x00, //":"=1AH
0x00,0x56,0x36,0x00,0x00, //";"=1BH
0x08,0x14,0x22,0x41,0x00, //"<"=1CH
0x14,0x14,0x14,0x14,0x14, //"="=1DH
0x00,0x41,0x22,0x14,0x08, //">"=1EH
0x02,0x01,0x51,0x09,0x06, //"?"=1FH
0x32,0x49,0x79,0x41,0x3E, //"@"=20H
0x7E,0x11,0x11,0x11,0x7E, //"A"=21H
0x41,0x7F,0x49,0x49,0x36, //"B"=22H
0x3E,0x41,0x41,0x41,0x22, //"C"=23H
0x41,0x7F,0x41,0x41,0x3E, //"D"=24H
0x7F,0x49,0x49,0x49,0x49, //"E"=25H
0x7F,0x09,0x09,0x09,0x01, //"F"=26H
0x3E,0x41,0x41,0x49,0x7A, //"G"=27H
0x7F,0x08,0x08,0x08,0x7F, //"H"=28H
0x00,0x41,0x7F,0x41,0x00, //"I"=29H
0x20,0x40,0x41,0x3F,0x01, //"J"=2AH
0x7F,0x08,0x14,0x22,0x41, //"K"=2BH
0x7F,0x40,0x40,0x40,0x40, //"L"=2CH
0x7F,0x02,0x0C,0x02,0x7F, //"M"=2DH
0x7F,0x04,0x08,0x10,0x7F, //"N"=2EH
0x3E,0x41,0x41,0x41,0x3E, //"O"=2FH
0x7F,0x09,0x09,0x09,0x06, //"P"=30H
0x3E,0x41,0x51,0x21,0x5E, //"Q"=31H
0x7F,0x09,0x19,0x29,0x46, //"R"=32H
0x26,0x49,0x49,0x49,0x32, //"S"=33H
0x01,0x01,0x7F,0x01,0x01, //"T"=34H
0x3F,0x40,0x40,0x40,0x3F, //"U"=35H
0x1F,0x20,0x40,0x20,0x1F, //"V"=36H
0x7F,0x20,0x18,0x20,0x7F, //"W"=37H
0x63,0x14,0x08,0x14,0x63, //"X"=38H
0x07,0x08,0x70,0x08,0x07, //"Y"=39H
0x61,0x51,0x49,0x45,0x43, //"Z"=3AH
0x00,0x7F,0x41,0x41,0x00, //"["=3BH
0x02,0x04,0x08,0x10,0x20, //"\"=3CH
0x00,0x41,0x41,0x7F,0x00, //"]"=3DH
0x04,0x02,0x01,0x02,0x04, //"^"=3EH
0x40,0x40,0x40,0x40,0x40, //"_"=3FH
0x01,0x02,0x04,0x00,0x00, //"|"=40H
0x20,0x54,0x54,0x54,0x78, //"a"=41H
0x7F,0x48,0x44,0x44,0x38, //"b"=42H
0x38,0x44,0x44,0x44,0x20, //"c"=43H
0x38,0x44,0x44,0x48,0x7F, //"d"=44H
0x38,0x54,0x54,0x54,0x18, //"e"=45H
0x08,0x7E,0x09,0x01,0x02, //"f"=46H
0x0C,0x52,0x52,0x52,0x3E, //"g"=47H
0x7F,0x08,0x04,0x04,0x78, //"h"=48H
0x00,0x44,0x7D,0x40,0x00, //"i"=49H
0x20,0x40,0x44,0x3D,0x00, //"j"=4AH
0x00,0x7F,0x10,0x28,0x44, //"k"=4BH
0x00,0x41,0x7F,0x40,0x00, //"l"=4CH
0x7C,0x04,0x78,0x04,0x78, //"m"=4DH
0x7C,0x08,0x04,0x04,0x78, //"n"=4EH
0x38,0x44,0x44,0x44,0x38, //"o"=4FH
0x7C,0x14,0x14,0x14,0x08, //"p"=50H
0x08,0x14,0x14,0x18,0x7C, //"q"=51H
0x7C,0x08,0x04,0x04,0x08, //"r"=52H
0x48,0x54,0x54,0x54,0x20, //"s"=53H
0x04,0x3F,0x44,0x40,0x20, //"t"=54H
0x3C,0x40,0x40,0x3C,0x40, //"u"=55H
0x1C,0x20,0x40,0x20,0x1C, //"v"=56H
0x3C,0x40,0x30,0x40,0x3C, //"w"=57H
0x44,0x28,0x10,0x28,0x44, //"x"=58H
0x1C,0xA0,0xA0,0x90,0x7C, //"y"=59H
0x44,0x64,0x54,0x4C,0x44, //"z"=5AH
0x00,0x08,0x36,0x41,0x00, //"{"=5BH
0x00,0x00,0x77,0x00,0x00, //"|"=5CH
0x00,0x41,0x36,0x08,0x00, //"}"=5DH
0x08,0x08,0x2A,0x1C,0x08, //"->"=5EH
0x08,0x1C,0x2A,0x08,0x08, //"<-"=5FH
};
//=================================
//=======================================
void delay(uchar n)
{
uchar i,j;
for (i=0; i<n; i++)
{
for(j=0; j<255;j++){}
}
}
//======================================
//====================================
// LCM WRITE AND READ COMMAD
//===================================
///========== 忙标志 =============/
//#pragma disable //保证程序在对信号量进行操作期间不被中断,避免发生错误
void busy()
{
uchar dat;
set_Bit(pcont,rw);
clr_Bit(pcont,rs); //rs=0,rw=1;
do
{
set_Bit(pcont,e); // e=1;
nop();
nop();
DDRC&= ~0x80;
nop();
nop();
dat=pdin;
nop();
nop();
clr_Bit(pcont,e); // e=0;
}
while ((dat&0x80)!=0);
DDRC=0xff;
}
//=========================================
void IC_select(uchar m)
{
switch (m)
{
case 0:
clr_Bit(pcont,cs2);
set_Bit(pcont,cs1); //cs1=1,cs2=0; //select IC1
break;
case 1:
clr_Bit(pcont,cs1);
set_Bit(pcont,cs2); //cs1=0,cs2=1; //select IC2
break;
case 2:
set_Bit(pcont,cs1);
set_Bit(pcont,cs2); //cs1=1,cs2=1; //select IC1 and IC2
break;
}
}
//=============== 写数据 ==============/
//#pragma disable
void write(uchar dat,uchar m)
{
IC_select(m);
busy();//delay(1); //busy();
nop();
nop();
clr_Bit(pcont,rw);
set_Bit(pcont,rs); //rs=1,rw=0;
pdout=dat; //P1=dat;
set_Bit(pcont,e); // e=1;
nop();
nop();
clr_Bit(pcont,e); //e=0;
clr_Bit(pcont,cs1);
clr_Bit(pcont,cs2); //cs1=1,cs2=1;
}
//============ 写数据========== //
//#pragma disable
void ctrl(uchar dat,uchar m)
{
IC_select(m);
busy();//delay(1); //busy();
nop();
nop();
clr_Bit(pcont,rw);
clr_Bit(pcont,rs); //rs=0,rw=0;
nop();
set_Bit(pcont,e); // e=1;
nop();
nop();
pdout=dat; //P1=dat;
nop();
nop();
clr_Bit(pcont,e); //e=0;
clr_Bit(pcont,cs1);
clr_Bit(pcont,cs2); //cs1=0,cs2=0;
}
//========== 读数据 ===============/
//#pragma disable
uchar read(uchar m)
{
uchar dat;
IC_select(m);
busy(); //delay(1); // busy();
nop();
nop();
set_Bit(pcont,rw);
set_Bit(pcont,rs); //rs=1,rw=1;
set_Bit(pcont,e); // e=1;
nop();
nop();
dat=pdin;
nop();
nop();
clr_Bit(pcont,e); //e=0;
clr_Bit(pcont,cs1);
clr_Bit(pcont,cs2); //cs1=0,cs2=0;
return(dat);
}
//==============================================
//Clear display
//==============================================
void cleardisplay()
{
uchar i,w;
for(i=0;i<8;i++)
{
ctrl(i|0xb8,2); //页地址设置 //ctrl(i+z,2); //页地址设置//
ctrl(0xc0,2);
ctrl(0x40,2); //设定列地址//
for(w=0;w<64;w++)
{write(0,2); }
}
}
//====================================
void lcd_init()
{
clr_Bit(pcont1,rst); //reset=0;
delay(1);
set_Bit(pcont1,rst); // reset=1;
ctrl(0x3f,2); //显示开关
cleardisplay(); //清显示
}
////////////////////////////////////////////////
//在x 列地址中写入 显示数据
// x地址,dat 显示数据,s (0或/ 1与/ 2异或 3替换)
///////////////////////////////////////////////
//if (tinib[1]==1) d=~d; //reverse display
//#pragma disable
void disp(uchar x,uchar dat,uchar s)
{
uchar temp,i;
if(x<64){i=0;} // 左半屏
else {i=1;} // 右半屏
ctrl(x|0x40,i); //set column address
if(s==3) {temp=dat;}
else
{
temp=read(i); //read display RAM
temp=read(i);
switch (s)
{
case 0:
temp=(dat|temp);
break;
case 1:
// dat=~dat;
temp=(dat&temp);
break;
}
}
ctrl(x|0x40,i);
write(temp,i);
}
//==============================================
//先设字符的首地址该地址,以字符的左上角的点为起始
//display 6x8,8x8 dots 子程序
//writetext (x地址,y地址,显示数据,显示/消隐)
//==============================================
void wtext8x8(uchar da,uchar s) //
{
// uchar a,c,i,ii,yy,dat,temp, col_x,row_y,;
uchar a,i,yy,dat,temp, col_x,row_y;
col_x=column*6;
row_y=row*8;
a=row_y%8;
yy=(row_y/8)|0xb8;
if (a==0)
{
ctrl(yy,0); //set page address
ctrl(yy,1); //set page address
for(i=0;i<5;i++)
{
dat=pgm_read_byte(&t5x8[(da-0x20)*5+i]);
//dat=t5x8[(da-0x20)*5+i];
disp(col_x+i,dat,s);
}
}
else
{
for(i=0;i<5;i++)
{
ctrl(yy,0); //set page address
ctrl(yy,1); //set page address
temp=pgm_read_byte(&t5x8[(da-0x20)*5+i]);
// temp=t5x8[(da-0x20)*5+i];
dat=temp<<a;
disp(col_x+i,dat,s);
ctrl(yy+1,0); //set page address
ctrl(yy+1,1); //set page address
dat=temp>>(8-a);
disp(col_x+i,dat,s);
}
}
}
/*
void wtext8x8(uchar col_x,uchar row_y,uchar da, uchar s) //
{
uchar a,c,i,ii,yy,dat,temp;
a=row_y%8;
yy=(row_y/8)|0xb8;
if (a==0)
{
ctrl(yy,0); //set page address
ctrl(yy,1); //set page address
for(i=0;i<5;i++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -