⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tg_4bitlcd.c

📁 嵌入式LCD驱动程序的实现top01_pac01
💻 C
📖 第 1 页 / 共 3 页
字号:
//===================================================================
// This file contains some basic LCD functions (4bit mode).         =
// The R/W-pin of the LCD is permanently set to "write".            =
//                                                                  =
// Used MCU : Intel D87C51FA ( 256 Byte RAM, 8 KByte EPROM,         =
//                             3 Timer, UART, @ 11.0592 MHz )       =
//                                                                  =
// Compiler commandline : sdcc program.c --stack-after-data         =
// Compiler version SDCC V2.19Ba                                    =
//===================================================================

//===================================================================
// Port-map of the MCU :                                            =
//                                                                  =
// P0_0 -> unused                                                   =
// P0_1 -> unused                                                   =
// P0_2 -> unused                                                   =
// P0_3 -> unused                                                   =
// P0_4 -> unused                                                   =
// P0_5 -> unused                                                   =
// P0_6 -> unused                                                   =
// P0_7 -> unused                                                   =
//                                                                  =
// P1_0 -> unused                                                   =
// P1_1 -> unused                                                   =
// P1_2 -> unused                                                   =
// P1_3 -> unused                                                   =
// P1_4 -> unused                                                   =
// P1_5 -> unused                                                   =
// P1_6 -> unused                                                   =
// P1_7 -> unused                                                   =
//                                                                  =
// P2_0 -> unused                                                   =
// P2_1 -> unused                                                   =
// P2_2 -> LCD RS                                                   =
// P2_3 -> LCD E                                                    =
// P2_4 -> LCD D4                                                   =
// P2_5 -> LCD D5                                                   =
// P2_6 -> LCD D6                                                   =
// P2_7 -> LCD D7                                                   =
//                                                                  =
// P3_0 -> [RXD]  unused                                            =
// P3_1 -> [TXD]  unused                                            =
// P3_2 -> [INT0] unused                                            =
// P3_3 -> [INT1] unused                                            =
// P3_4 -> [T0]   unused                                            =
// P3_5 -> [T1]   unused                                            =
// P3_6 -> [WR]   unused                                            =
// P3_7 -> [RD]   unused                                            =
//                                                                  =
//===================================================================


// INCLUDES =========================================================
#include <regc51fx.h>     // Definitions of registers, SFRs and Bits
// END INCLUDES =====================================================


// DEFINES ==========================================================
#define LCD_DATA  P2      // Dataport of LCD-Display (D4..D7) 
#define LCD_RS    P2_2    // Register Select of LCD-Display
#define LCD_E     P2_3    // Enable of LCD-Display
#define CTRL_REG  0       // Select instruction register
#define DATA_REG  1       // Select data register
#define BLINK     0x01    // Alias for blinking cursor
#define NOBLINK   0x00    // Alias for non blinking cursor
#define SHOW      0x02    // Alias for cursor on
#define HIDE      0x00    // Alias for cursor off
#define ON        0x04    // Alias for display on
#define OFF       0x00    // Alias for display off
                                                                                    
// END DEFINES ======================================================


// ISR-Prototypes ===================================================
void External0_ISR(void) interrupt 0;         // ISR for the external input INT0
void Timer0_ISR(void)    interrupt 1 using 2; // ISR for Timer0 overflow
void External1_ISR(void) interrupt 2;         // ISR for the external input INT1
void Timer1_ISR(void)    interrupt 3 using 3; // ISR for Timer1 overflow
void Serial_ISR(void)    interrupt 4 using 1; // ISR for serial reception
void Timer2_ISR(void)    interrupt 5;         // ISR for Timer2 overflow
// END ISR-Prototypes ===============================================


// Prototypes =======================================================
void init_MCU(void);                    // Initialize the MCU

void delay(unsigned int time_100us);    // Timer dependend delay-routine
void putchar(unsigned char value);      // Send a character via UART
void UART_puts(unsigned char *text);    // Sends a string to the UART
void init_LCD(void);                    // Initialize the LCD display
void clrscr(void);                      // Clears LCD screen
void LCD_putchar(unsigned char value);  // Writes a character to display
// Prints a text to x/y position
void LCD_printxy(unsigned char x,unsigned char y, unsigned char *text);
// Controls the display
void control_LCD(unsigned char dsp,unsigned char blink,unsigned char cursor);
// Sets LCD write position
void gotoxy(unsigned char x,unsigned char y);

// END Prototypes ===================================================


// Globals ==========================================================

// Table to select DD-RAM address (including instruction and address)
// 0x00..0x0F -> Line 1, 0x40..0x4F -> Line 2
static unsigned char code LOCATION[2][16] = { {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
                                               0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F},
                                              {0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,
                                               0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF} };

volatile unsigned int  DELAY;                   // Global delaytime

// END Globals ======================================================


/********************************************************************/
/* Function    : External0_ISR()                                ISR */
/*------------------------------------------------------------------*/
/* Description : Interrupt-Service-Routine on vector #0 for         */
/*               handling interrupt requests on external pin P3_2.  */
/*------------------------------------------------------------------*/
/* Author      : Thorsten Godau  NT8                                */
/*------------------------------------------------------------------*/
/* Input       : none                                               */
/*------------------------------------------------------------------*/
/* Returnvalue : none                                               */
/*------------------------------------------------------------------*/
/* History     : 06/99    V1.0 Basic routine                        */
/*                                                                  */
/********************************************************************/
void External0_ISR(void) interrupt 0 
{
// Safety-routine
_asm
  nop
_endasm;
 
return;  
}


/********************************************************************/
/* Function    : Timer0_ISR()                                   ISR */
/*------------------------------------------------------------------*/
/* Description : Interrupt-Service-Routine on vector #1 for         */
/*               handling Timer0 interrupts. Register set #2 is     */
/*               used to store important registers.                 */
/*               The routine is called every 200祍.                 */
/*------------------------------------------------------------------*/
/* Author      : Thorsten Godau  NT8                                */
/*------------------------------------------------------------------*/
/* Input       : none                                               */
/*------------------------------------------------------------------*/
/* Returnvalue : none                                               */
/*------------------------------------------------------------------*/
/* History     : 06/99    V1.0 Basic routine                        */
/*                                                                  */
/********************************************************************/
void Timer0_ISR(void) interrupt 1 using 2
{
ET0 = 0;                     // Disable Timer0-interrupt

if ( DELAY > 0 ) DELAY--;    // Timebase ticks for delay-routine

ET0 = 1;                     // Enable Timer0-interrupt

return;
}


/********************************************************************/
/* Function    : External1_ISR()                                ISR */
/*------------------------------------------------------------------*/
/* Description : Interrupt-Service-Routine on vector #2 for         */
/*               handling interrupt requests on external pin P3_3.  */
/*               Free for further use.                              */
/*------------------------------------------------------------------*/
/* Author      : Thorsten Godau  NT8                                */
/*------------------------------------------------------------------*/
/* Input       : none                                               */
/*------------------------------------------------------------------*/
/* Returnvalue : none                                               */
/*------------------------------------------------------------------*/
/* History     : 06/99    V1.0 Basic routine                        */
/*                                                                  */
/********************************************************************/
void External1_ISR(void) interrupt 2
{
// Safety-routine
_asm
  nop
_endasm;
  
return;
}


/********************************************************************/
/* Function    : Timer1_ISR()                                   ISR */
/*------------------------------------------------------------------*/
/* Description : Interrupt-Service-Routine on vector #3 for         */
/*               handling Timer1 interrupts. Register set #3 is     */
/*               used to store important registers.                 */
/*               Free for further use.                              */
/*------------------------------------------------------------------*/
/* Author      : Thorsten Godau  NT8                                */
/*------------------------------------------------------------------*/
/* Input       : none                                               */
/*------------------------------------------------------------------*/
/* Returnvalue : none                                               */
/*------------------------------------------------------------------*/
/* History     : 06/99    V1.0 Basic routine                        */
/*                                                                  */
/********************************************************************/
void Timer1_ISR(void) interrupt 3 using 3
{
ET1 = 0;                     // Disable Timer1-interrupt

// Safety-routine
_asm
  nop

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -