?? tg_4bitlcd.c
字號:
_endasm;
ET1 = 1;
return;
}
/********************************************************************/
/* Function : Serial_ISR() ISR */
/*------------------------------------------------------------------*/
/* Description : Interrupt-Service-Routine on vector #4 for */
/* handling serial interrupts. Register set #1 is */
/* used to store important registers. */
/*------------------------------------------------------------------*/
/* Author : Thorsten Godau NT8 */
/*------------------------------------------------------------------*/
/* Input : none */
/*------------------------------------------------------------------*/
/* Returnvalue : none */
/*------------------------------------------------------------------*/
/* History : 06/99 V1.0 Basic routine */
/* */
/********************************************************************/
void Serial_ISR(void) interrupt 4 using 1
{
// Safety-routine
_asm
nop
_endasm;
return;
}
/********************************************************************/
/* Function : Timer2_ISR() ISR */
/*------------------------------------------------------------------*/
/* Description : Interrupt-Service-Routine on vector #5 for */
/* handling Timer2 interrupts. */
/* Routine is not used, because Timer2 generates */
/* the baudrate for the serial communication. */
/*------------------------------------------------------------------*/
/* Author : Thorsten Godau NT8 */
/*------------------------------------------------------------------*/
/* Input : none */
/*------------------------------------------------------------------*/
/* Returnvalue : none */
/*------------------------------------------------------------------*/
/* History : 06/99 V1.0 Basic routine */
/* */
/********************************************************************/
void Timer2_ISR(void) interrupt 5
{
// Safety-routine
_asm
nop
_endasm;
return;
}
/********************************************************************/
/* Function : init_MCU() SUB */
/*------------------------------------------------------------------*/
/* Description : Routine initializes the used MCU registers, */
/* the timers and the global variables. */
/* Baudrate calculation : */
/* RCAP2 = 65536 - ( Quarz / 32 * Baud ) */
/* Timer 0/1 autoreload-register THx calculation : */
/* THx = Timebase * Quarz / 12 */
/*------------------------------------------------------------------*/
/* Author : Thorsten Godau NT8 */
/*------------------------------------------------------------------*/
/* Input : none */
/*------------------------------------------------------------------*/
/* Returnvalue : none */
/*------------------------------------------------------------------*/
/* History : 06/99 V1.0 Basic routine */
/* */
/********************************************************************/
void init_MCU(void)
{
EA = 0; // Disable all interrupts
ET0 = 0; // Disable Timer 0 interrupt
ET1 = 0; // Disable Timer 1 interrupt
ES = 0; // Disable Serial interrupt
TR0 = 0; // Stop Timer 0
TR1 = 0; // Stop Timer 1
TR2 = 0; // Stop Baudrate-Generator Timer 2
// Set all pins to input-mode
P0 = 0xFF;
P1 = 0xFF;
P2 = 0xFF;
P3 = 0xFF;
// Timer 0 & 1
TL0 = 0x00; // MUST be initialized for the firt time with 0
TH0 = 0xA4; // Tick every 100祍
TL1 = 0x00; // MUST be initialized for the firt time with 0
TH1 = 0x48; // Tick every 200祍
TMOD = 0x22; // Autoreload for both Timer 0 & 1
// Timer 2 (used for baudrate-generation)
C_T2 = 0; // Timer-Mode
RCLK = 1;
TCLK = 1; // Set mode to Baudrate-Generator
SM1 = 1;
SM0 = 0; // Set UART to 8N1
REN = 1; // Enable UART reception
RCAP2H = 0xFF;
RCAP2L = 0xEE; // Set Baudrate to 19200Bd at fq = 11.0592MHz (9k6 -> RCAP2 = 0xFFDC)
RI = 0; // Clear Receive-Interrupt-Flag
TI = 0; // Clear Transmit-Interrupt-Flag
// Initialize globals
DELAY = 0;
TR0 = 1; // Start Timer 0
TR1 = 1; // Start Timer 1
TR2 = 1; // Start Baudrate-Generator Timer 2
ET0 = 1; // Enable Timer 0 interrupt
ET1 = 1; // Enable Timer 1 interrupt
ES = 1; // Enable Serial interrupt
EA = 1; // Enable all interrupts
return;
}
/********************************************************************/
/* Function : init_LCD() SUB */
/*------------------------------------------------------------------*/
/* Description : Routine initializes the LCD display recommended */
/* in the datasheet (4 Bit initialization) */
/*------------------------------------------------------------------*/
/* Author : Thorsten Godau NT8 */
/*------------------------------------------------------------------*/
/* Input : none */
/*------------------------------------------------------------------*/
/* Returnvalue : none */
/*------------------------------------------------------------------*/
/* History : 06/99 V1.0 Basic routine */
/* 09/99 V1.1 Timing correction of init */
/* */
/********************************************************************/
void init_LCD(void)
{
delay(200); // Wait 20ms
LCD_E = 0;
LCD_RS = CTRL_REG; // Switch to inruction register
//Set LCD_DATA to high nibble of Software Reset
LCD_DATA = (LCD_DATA&0x0F)|0x30;
LCD_E = 1; LCD_E = 0; // Write data to display
delay(50); // Wait 5ms
LCD_E = 1; LCD_E = 0; // Write data to display again (SW Reset)
delay(50); // Wait 5ms
LCD_E = 1; LCD_E = 0; // Write data to display again (SW Reset)
delay(50); // Wait 5ms
// Set LCD_DATA to high nibble of Function Set (4Bit)
LCD_DATA = (LCD_DATA&0x0F)|0x20;
LCD_E = 1; LCD_E = 0; // Write data to display
delay(4);
// Set LCD_DATA to high nibble of Function Set : 4 bit, 2 lines, 5*7 font
LCD_DATA = (LCD_DATA&0x0F)|0x20;
LCD_E = 1; LCD_E = 0; // Write data to display
// Set LCD_DATA to lower nibble of Function Set : 4 bit, 2 lines, 5*7 font
LCD_DATA = (LCD_DATA&0x0F)|0x80;
LCD_E = 1; LCD_E = 0; // Write data to display
delay(4); // Wait 400祍
// Set LCD_DATA to high nibble of Display On/Off Control : display off, cursor off, don磘 blink
LCD_DATA = (LCD_DATA&0x0F)|0x00;
LCD_E = 1; LCD_E = 0; // Write data to display
// Set LCD_DATA to lower nibble of Display On/Off Control : display off, cursor off, don磘 blink
LCD_DATA = (LCD_DATA&0x0F)|0x80;
LCD_E = 1; LCD_E = 0; // Write data to display
delay(4); // Wait 400祍
// Set LCD_DATA to high nibble of Clear Display
LCD_DATA = (LCD_DATA&0x0F)|0x00;
LCD_E = 1; LCD_E = 0; // Write data to display
// Set LCD_DATA to lower nibble of Clear Display
LCD_DATA = (LCD_DATA&0x0F)|0x10;
LCD_E = 1; LCD_E = 0; // Write data to display
delay(50); // Wait 5ms
// Set LCD_DATA to high nibble of Entry Mode Set : increment DD-RAM address, move cursor
LCD_DATA = (LCD_DATA&0x0F)|0x00;
LCD_E = 1; LCD_E = 0; // Write data to display
// Set LCD_DATA to lower nibble of Entry Mode Set : increment DD-RAM address, move cursor
LCD_DATA = (LCD_DATA&0x0F)|0x60;
LCD_E = 1; LCD_E = 0; // Write data to display
delay(4); // Wait 400祍
return;
}
/********************************************************************/
/* Function : control_LCD(dsp,blink,cursor) SUB */
/*------------------------------------------------------------------*/
/* Description : Routine controls the screen */
/*------------------------------------------------------------------*/
/* Author : Thorsten Godau NT8 */
/*------------------------------------------------------------------*/
/* Input : unsigned char dsp = ON -> Display on */
/* OFF -> Display off */
/* unsigned char blink = BLINK -> Cursor blinks */
/* NOBLINK-> Cursor not blinks */
/* unsigned char cursor = SHOW -> Cursor visible */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -