资源预览内容
第1页 / 共9页
第2页 / 共9页
第3页 / 共9页
第4页 / 共9页
第5页 / 共9页
第6页 / 共9页
第7页 / 共9页
第8页 / 共9页
第9页 / 共9页
亲,该文档总共9页全部预览完了,如果喜欢就下载吧!
资源描述
/*/* Main.C */*/* W-AP002 MPLAB C18 Advance Workshop */* Written by: Richard Yang */* Sr. Corporate Applications Engr.*/* Microchip Technology Inc. */* Date: 16 January 2003 */* Revision: 1 */*/*#include #include #include P18F_LCD.hvoid InitializePORT(void);#pragma idata access My_RAM_1near char LCD_RAM_MSG =Richard Yang;near unsigned char LCD_Char=0;#pragma romdata RomDataconst rom char LCD_ROM_MSG =WAP-002 Workshop;#pragma code/*/* */* Main Program */* */*void main(void)InitializePORT( );OpenLCD( );putcLCD(!);while(1);/*/* Function: Initialize PORT */*void InitializePORT(void)PORTA=0x00;TRISA=0b11011011; / RA2 as LCD-E control, RA5 as CS Control for SPIPORTD=0x00;TRISD=0x00; / Set PORTD as Output port#pragma code#pragma romdata CONFIGconst rom unsigned char CONFIG1L=0xff ; / Dont care byteconst rom unsigned char CONFIG1H=0b00100010 ; / Disable OSC switch , XXXXX010 = HS Oscconst rom unsigned char CONFIG2L=0b00000001 ; / Disable PWRT , Disable BORconst rom unsigned char CONFIG2H=0b00000000 ; / Disable WDT timerconst rom unsigned char CONFIG3L=0xff ; / Dont care byteconst rom unsigned char CONFIG3H=0b00000000 ; / XXXXXXX0 = CCP2 RB3const rom unsigned char CONFIG4L=0b00000001 ; / 0XXXXXXX Backgroung Debug Enable ( ICD )const rom unsigned char CONFIG4H=0xff ; / Dont care byteconst rom unsigned char CONFIG5L=0b00001111 ; / Not PROG code protectedconst rom unsigned char CONFIG5H=0b11000000 ; / Not EEPROM code protectedconst rom unsigned char CONFIG6L=0b00001111 ;const rom unsigned char CONFIG6H=0b11100000 ;const rom unsigned char CONFIG7L=0b00001111 ;const rom unsigned char CONFIG7H=0b01000000 ;#pragma romdata/ Declaration file for LCD related subroutines void OpenLCD (void) ;void WriteCmdLCD ( unsigned char ) ;void WriteDataLCD( unsigned char ) ;void putsLCD( char * ) ;void putrsLCD( const rom char * ) ;void putcLCD( unsigned char ) ;void puthexLCD( unsigned char ) ;void LCD_Set_Cursor( unsigned char , unsigned char ) ;void LCD_CMD_W_Timing( void ) ;void LCD_L_Delay( void ) ;void LCD_S_Delay( void ) ;void LCD_DAT_W_Timing ( void ) ;#include #include #include P18F_LCD.h/ Defines for I/O ports that provide LCD data & control/ PORTD0:3DB4:7: Higher order 4 lines data bus with bidirectional/ : DB7 can be used as a BUSY flag/ PORTA,2 E : LCD operation start signal control / PORTD,5 RW: LCD Read/Write control/ PORTD,4 RS: LCD Register Select control/ : 0 for Instrunction register (Write), Busy Flag (Read)/ : 1 for data register (Read/Write)/#define CPU_SPEED 16 / CPU speed is 16 Mhz !#define LCD_RS PORTDbits.RD4 / The definition of control pins#define LCD_RW PORTDbits.RD5#define LCD_E PORTAbits.RA2#define LCD_DATA LATD / PORTD0:3 as LCD DB4:7/#define LCD_CTRL LATA#define DIR_LCD_DATA TRISD/ LCD Module commands#define DISP_2Line_8Bit 0b00111000#define DISP_2Line_4Bit 0b00101000#define DISP_ON 0x00C / Display on#define DISP_ON_C 0x00E / Display on, Cursor on#define DISP_ON_B 0x00F / Display on, Cursor on, Blink cursor#define DISP_OFF 0x008 / Display off#define CLR_DISP 0x001 / Clear the Display#define ENTRY_INC 0x006 /#define ENTRY_INC_S 0x007 /#define ENTRY_DEC 0x004 /#define ENTRY_DEC_S 0x005 /#define DD_RAM_ADDR 0x080 / Least Significant 7-bit are for address#define DD_RAM_UL 0x080 / Upper Left coner of the Display#pragma udataunsigned char Temp_CMD ;unsigned char Str_Temp ;unsigned char Out_Mask ;#pragma codevoid OpenLCD(void)/ADCON1=(ADCON1 & 0xF0)|0b00001110; / Set AN0 for analog inputLCD_E=0;LCD_DATA = 0x00; / LCD DB4:7 & RS & R/W LowDIR_LCD_DATA = 0x00; / LCD DB4:7 & RS & R/W are output functionTRISAbits.TRISA2=0; / Set E pin as outputLCD_DATA = 0b00000011 ;LCD_CMD_W_Timing() ;LCD_L_Delay() ;LCD_DATA = 0b00000011 ;LCD_CMD_W_Timing() ;LCD_L_Delay() ;LCD_DATA = 0b00000011 ;LCD_CMD_W_Timing() ;LCD_L_Delay() ;LCD_DATA = 0b00000010 ;LCD_CMD_W_Timing() ;LCD_L_Delay() ;WriteCmdLCD(DISP_2Line_4Bit) ;LCD_S_Delay() ;WriteCmdLCD(DISP_ON) ;LCD_S_Delay() ;WriteCmdLCD(ENTRY_INC) ;LCD_S_Delay() ;WriteCmdLCD(CLR_DISP) ;LCD_L_Delay() ;/*/ _ _/ RS _-4 ; / Send high nibble to LCD busLCD_DATA= (LCD_DATA & 0xF0)|Temp_CMD ;LCD_CMD_W_Timing () ;Temp_CMD = LCD_CMD & 0x0F ; / Send low nibble to LCD busLCD_DATA= (LC
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号