📄 main.c
字号:
//==============================================================================
// DEVICE = PICC-18
// VERSION = 1.0
// DATE = 11.08.2007
// LAST CHANGE = -
// Developer = Keith Yuen
// =============================================================================
// Description: KS0108 GLCD Driver Demo for PIC18F4455
// =============================================================================
#include <pic18.h>
#include "delay.h"
#include "glcd.h"
void PortInit(void)
{
TRISD = 0b00000000;
TRISC = 0b00000000;
TRISB = 0b00000000;
}
void TimerInit(void)
{
//TIMER
TMR0IE = 1;
TMR0H = 0xD1; //1ms
TMR0L = 0xDF;
T0CON = 0x08; //
TMR0ON = 1; //ON TIMER
}
void main()
{
//OFF WatchDog
SWDTEN = 0;
//INTERRUPT
INTCON = 0; // reset all the flag bits for all the interrupts
GIE = 1; // global interrupt enable bit (1: enable all)
//ADC
ADCON0 = 0x41; //AN1
TimerInit();
PortInit();
DelayMs(50);
//GLCD Init
GLCD_Init();
//Char
GLCD_SetPos(0, 10);
GLCD_WriteChar('!');
GLCD_WriteChar('#');
GLCD_WriteDec2(' ');
GLCD_WriteChar('-');
GLCD_WriteHex(' ');
//String
GLCD_WriteString("0123456789", 0, 40);
GLCD_WriteString("abcdefghijklm", 1, 40);
GLCD_WriteString("nopqrstuvwxyz", 2, 40);
GLCD_WriteString("ABCDEFGHIJKLM", 3, 40);
GLCD_WriteString("NOPQRSTUVWXYZ", 4, 40);
//Align String
GLCD_WriteAlignString("ALIGN LEFT", 5, GLCD_ALIGN_LEFT);
GLCD_WriteAlignString("ALIGN RIGHT", 6, GLCD_ALIGN_RIGHT);
GLCD_WriteAlignString("ALIGN CENTER", 7, GLCD_ALIGN_CENTER);
//Combine data
GLCD_SetPos(7, 10);
GLCD_WriteData(0x11);
GLCD_SetPos(7, 10);
GLCD_WriteCombineData(0x88); //data become 0x99
//draw a dot on x,y position
GLCD_WriteDot(1,2);
GLCD_WriteDot(2,3);
GLCD_WriteDot(3,4);
GLCD_WriteDot(4,5);
GLCD_WriteDot(5,6);
GLCD_WriteDot(1,6);
GLCD_WriteDot(2,5);
GLCD_WriteDot(3,4);
GLCD_WriteDot(4,3);
GLCD_WriteDot(5,2);
while(1)
{
}
}
//1ms interrupt
void interrupt prv_int(void)
{
static unsigned char tick10ms = 0;
static unsigned char tick1ms = 0;
static unsigned char y=0;
if (!TMR0IF)
return;
TMR0IF = 0;
TMR0H = 0xD1; //1ms
TMR0L = 0xDF;
tick1ms++;
if (tick1ms == 10)
{
tick1ms = 0;
////////////////////////
//10ms ACTION HERE:
tick10ms++;
if (tick10ms == 100)
{
tick10ms = 0;
////////////////////////
//1s ACTION HERE:
//Scrolling
GLCD_SetStartLine(y++);
if(y==64)y=0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -