📄 glcd.c
字号:
/*******************************************************************
********************************************************************
***** *****
***** PIC16877 with Graph LCD *****
***** *****
********************************************************************
*******************************************************************/
//#include <16F877.h>
#define WR 0x01; //PORTC.0;
#define RD 0x02; //PORTC.1;
#define CE 0x04; //PORTC.2;
#define CD 0x08; //PORTC.3;
#define RST 0x10; //PORTC.4;
#define FS 0x20; //PORTC.5;
#define R1 0x01; //PORTB.0;
#define Y1 0x02; //PORTB.1;
#define G1 0x04; //PORTB.2;
#define R2 0x08; //PORTB.3;
#define Y2 0x10; //PORTB.4;
#define G2 0x20; //PORTB.5;
#define MaxColumn 128;
#define Column 16;
#define MaxRow 64;
/*enum {}; // Timer identifiers
#define FreqOsc 1000000 // Oscillator frequenzy
#define FreqTimer 100 // Timer frequency, 1000 or 100 Hz
#define TimerType uns16 // uns8, uns16 or uns24
#define NoOfTimers 4 // 1 .. 8
#define DELAY_TYPE 1
//#include "delay.h" */
char low8bit,high8bit,ShowGraphic,ShowAdd,GrAdd;
char set1,set2,Value,State1,State2;
char TimerA, TimerB,tCount,ticks;
bit Erase,TimeUp;
#include "int16CXX.H"
#pragma origin 4
interrupt int_server(void)
{
int_save_registers // W,status and PCLATH
if (T0IF)
{
if (TimerB != 0)
TimerB --;
tCount++;
if (tCount <= 6)
TMR0 = 20 ;
else
{
TimeUp = 1 ;
TMR0 = 40 ;
tCount = 0 ;
if (TimerA != 0)
TimerA --;
}
T0IF = 0 ;
}
int_restore_registers // w,status and PCLATH
}
void writecmd(char data)
{
PORTC |= CD ;
PORTC &= ~CE ;
PORTC &= ~WR ;
PORTC |= RD ;
PORTD = data ;
PORTC |= CE ;
PORTC |= WR ;
}
void writedata(char data)
{
PORTC &= ~CD ;
PORTC &= ~CE ;
PORTC &= ~WR ;
PORTC |= RD ;
PORTD = data ;
PORTC |= CE ;
PORTC |= WR ;
}
void readstatus(char data)
{
PORTC |= CD ;
PORTC &= ~CE ;
PORTC &= ~RD ;
PORTC |= WR ;
PORTD = data ;
PORTC |= CE ;
PORTC |= RD ;
}
void readdata(char data)
{
PORTC &= ~CD ;
PORTC &= ~CE ;
PORTC &= ~RD ;
PORTC |= WR ;
PORTD = data ;
PORTC |= CE ;
PORTC |= RD ;
}
void writedata2()
{
writedata(low8bit);
writedata(high8bit);
}
void initlcd()
{
low8bit = 0;
high8bit = 0;
writedata2();
writecmd(0x40);
low8bit = 0;
high8bit = 0x40;
writedata2();
writecmd(0x42);
low8bit = Column;
high8bit = 0;
writedata2();
writecmd(0x41);
low8bit = Column;
high8bit = 0;
writedata2();
writecmd(0x43);
writecmd(0x80); //0x80 External CG RAM mode, OR
/*SETMODE ; ** SET MODE - MANY OPTIONS, see EPE text **
; movlw %10000000 ; 0x80 External CG RAM mode, OR
; movlw %10000011 ; 0x83 External CG RAM mode, AND
; movlw %10000001 ; 0x81 External CG RAM mode, XOR
; movlw %10000100 ; 0x84 text attribute mode
CALL SENDCMD ; send command */
}
static const char show[16] = {16,17,18,19,20,21,22,23,24,
25,26,27,28,29,30,31};
static const char st[32] = {7,192,15,224,7,64,3,128,
15,224,23,208,39,200,23,208,
15,224,7,192,15,224,12,96,
12,96,12,96,12,96,12,96};
static const char w1[32] = {7,192,15,240,7,224,3,128,
15,224,23,208,39,206,39,192,
39,192,39,192,7,192,12,96,
12,48,24,48,24,96,28,112};
static const char w2[32] = {7,192,15,240,7,224,3,128,
15,224,23,208,39,208,71,200,
135,196,7,192,12,192,12,192,
12,192,124,192,120,192,64,224};
static const char w3[32] = {7,192,15,240,7,224,3,128,
63,192,39,224,39,224,39,208,
7,200,7,192,6,96,6,48,
6,24,12,24,12,24,14,28};
void Show(void)
{ char tmp1,tmp2,tmp3,tmp4;
writecmd(0x9c); //graphic enable
//if (Erase)
//writecmd(0x83); //0x83 External CG RAM mode, and
// else
writecmd(0x80); //0x83 External CG RAM mode, or
tmp4 = GrAdd ;
low8bit = tmp4;
high8bit = 0x40;
writedata2();
writecmd(0x24);
writecmd(0xb0);
tmp3 = 0;
tmp1 = 16 ;
do {
tmp2 = 2 ;
do {
switch (ShowGraphic){
case 0 :
writedata(st[tmp3]);
break;
case 1 :
writedata(w1[tmp3]);
break;
case 2 :
writedata(w2[tmp3]);
break;
case 3 :
writedata(w3[tmp3]);
break;
}
tmp3 ++ ;
} while(-- tmp2);
tmp4 = 16 + tmp4 ;
writecmd(0xb2);
low8bit = tmp4;
high8bit = 0x40;
writedata2();
writecmd(0x24);
writecmd(0xb0);
} while(-- tmp1);
writecmd(0xb2);
}
void getset(void)
{
TRISD = 0x0f;
PORTC |= CE ;
PORTD = 0x1f;
set1 = PORTD;
set1 = PORTD;
set1 &= 0x0f;
PORTD = 0x2f;
set2 = PORTD;
set2 = PORTD;
set2 &= 0x0f;
TRISD = 0;
PORTD = 0;
}
void ShowValue(void)
{ char tmp1,tmp2,tmp3,tmp4;
tmp1=Value%10;
writecmd(0x9c);
tmp2=Value/10;
low8bit = ShowAdd ; // 2 and 10 add
high8bit = 0;
writedata2();
writecmd(0x24);
writecmd(0xb0);
if (tmp2==0)
writedata(0);
else
writedata(tmp2+16);
writedata(tmp1+16);
writecmd(0xb2);
}
void Fsm2(void)
{
switch (State2)
{
case 0:
if (TimerB==0)
{
ShowGraphic = 0 ;
Show();
State2 = 1 ;
TimerB=1;
}
break;
case 1:
if (TimerB==0)
{
ShowGraphic = 1 ;
Show();
State2 = 2 ;
TimerB=1;
}
break;
case 2:
if (TimerB==0)
{
ShowGraphic = 2 ;
Show();
State2 = 0 ;
TimerB=1;
}
break;
}
}
void Fsm1(void)
{
switch (State1)
{
case 0:
if (TimerA==0)
{
PORTB |= R2 ;
PORTB &= ~R1 ;
PORTB &= ~Y1 ;
PORTB &= ~Y2 ;
PORTB |= G1 ;
PORTB &= ~G2 ;
GrAdd = 0x00;
ShowGraphic = 0 ;
Show();
GrAdd = 0x08;
Fsm2();
getset();
Value = (set2*5) ;
ShowAdd = 2 ;
ShowValue();
State1 = 1 ;
TimerA=(set1*5);
}
break;
case 1:
Fsm2();
Value = TimerA ;
ShowAdd = 10 ;
ShowValue();
if (TimerA==0)
{
PORTB |= Y1 ;
PORTB &= ~R2 ;
PORTB &= ~G1 ;
PORTB &= ~Y2 ;
PORTB |= R2 ;
PORTB &= ~G2 ;
GrAdd = 0x08;
ShowGraphic = 0 ;
Show();
State1 = 2 ;
TimerA=15;
}
break;
case 2:
if (TimerA==0)
{
PORTB |= R1 ;
PORTB &= ~G1 ;
PORTB &= ~Y1 ;
PORTB &= ~Y2 ;
PORTB |= R2 ;
PORTB &= ~G2 ;
State1 = 3 ;
TimerA=5;
}
break;
case 3:
if (TimerA==0)
{
PORTB |= R1 ;
PORTB &= ~R2 ;
PORTB &= ~Y1 ;
PORTB &= ~Y2 ;
PORTB |= G2 ;
PORTB &= ~G1 ;
GrAdd = 0x08;
ShowGraphic = 0 ;
Show();
GrAdd = 0x00;
Fsm2();
getset();
Value = (set1*5) ;
ShowAdd = 10 ;
ShowValue();
State1 = 4 ;
TimerA = (set2*5);
}
break;
case 4:
Fsm2();
Value = TimerA ;
ShowAdd = 2 ;
ShowValue();
if (TimerA==0)
{
PORTB |= R1 ;
PORTB &= ~G1 ;
PORTB &= ~Y1 ;
PORTB &= ~G2 ;
PORTB |= Y2 ;
PORTB &= ~R2 ;
GrAdd = 0x00;
ShowGraphic = 0 ;
Show();
State1 = 5 ;
TimerA=15;
}
break;
case 5:
if (TimerA==0)
{
PORTB |= R1 ;
PORTB &= ~G2 ;
PORTB &= ~Y1 ;
PORTB &= ~Y2 ;
PORTB |= R2 ;
PORTB &= ~G1 ;
State1 = 0 ;
TimerA=5;
}
break;
}
}
void main()
// Program Control Function.
{ char tmp1,tmp2,tmp3,tmp4,tmp5;
set1 = 3;
set2 = 3;
TRISC = 0;
TRISB = 0;
PORTB = 0;
PORTC = 0;
TRISD = 0;
PORTD = 0;
PORTC &= ~RST ;
PORTC |= RST ;
PORTC &= ~FS ;
OPTION = 4 ;
ticks = 0 ;
TimeUp = 0 ;
tCount = 0 ;
TMR0 = 0 ;
initlcd(); // Initialise the LCD Display
tmp5 = 16;
Value = tmp5;
TimerA=0;
TimerB=0;
State1 = 0;
State2 = 0;
T0IE = 1 ;
GIE = 1 ;
while(1)
{
//show text
//writecmd(0x9c);
/* SETDISPLAY ; ** DISPLAY MODE ** SOME OPTIONS:
; 10010100'0x94 text on, graphic off, cursor & blink off
; %10011100 0x9c text on, graphic on, cursor & blink off
; %10011000 0x98 text off, graphic on, cursor & blink off
; %10010000 0x90 display off
; %1001xx10 0x92 cursor on, blink off
; %1001xx11 0x93 cursor on, blink on
; %100101xx 0x94 text on, graphic off
; %100110xx 0x98 text off, graphic on
; %100111xx 0x9c text on, graphic on */
Fsm1();
Fsm1();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -