; CC5X Version 3.1G, Copyright (c) B Knudsen Data ; C compiler for the PICmicro family ; ************ 27. Jun 2003 9:39 ************* processor 16F873 radix DEC TMR0 EQU 0x01 PORTA EQU 0x05 TRISA EQU 0x85 PORTB EQU 0x06 TRISB EQU 0x86 PSA EQU 3 T0SE EQU 4 T0CS EQU 5 Carry EQU 0 Zero_ EQU 2 RP0 EQU 5 RP1 EQU 6 RA2 EQU 2 RA3 EQU 3 RA5 EQU 5 PORTC EQU 0x07 TRISC EQU 0x87 ADCON1 EQU 0x9F ADON EQU 0 CHS0 EQU 3 CHS1 EQU 4 CHS2 EQU 5 ADFM EQU 7 x EQU 0x7F x_2 EQU 0x22 y EQU 0x24 z EQU 0x25 c EQU 0x20 data_char EQU 0x21 d EQU 0x20 data_char_2 EQU 0x21 GOTO main ; FILE d:\Pics\code\Delay.c ;/* ; 7/23/02 ; Nathan Seidle ; nathan.seidle@colorado.edu ; ; Delays for... Well, everything. ; ; 11-11 Updated the delays - now they actually delay what they say they should. ; ;*/ ;//#define Clock_4MHz ;#define Clock_20MHz ; ;//Really short delay ;void delay_us(uns16 x) ;{ delay_us ; ;#ifdef Clock_4MHz ; //Calling with 10us returns 69us ; for ( ; x > 0 ; x--); ;#endif ; ;#ifdef HS_Osc ; //Clocks out to 3us per x ; for ( ; x > 0 ; x--); m001 BCF 0x03,RP0 BCF 0x03,RP1 MOVF x,W IORWF x+1,W BTFSC 0x03,Zero_ GOTO m002 DECF x,1 INCF x,W BTFSC 0x03,Zero_ DECF x+1,1 GOTO m001 ;#endif ; ;} m002 RETURN ; ;//General short delay ;void delay_ms(uns16 x) ;{ delay_ms ; ;#ifdef Clock_4MHz ; //Clocks out at 1008us per 1ms ; int y; ; for ( ; x > 0 ; x--) ; for ( y = 0 ; y < 75 ; y++); ;#endif ; ;#ifdef HS_Osc ; uns8 y, z; ; //Clocks out to 999.4 us per 1ms ; //9.98 ms per 10ms ; for ( ; x > 0 ; x--) m003 BCF 0x03,RP0 BCF 0x03,RP1 MOVF x_2,W IORWF x_2+1,W BTFSC 0x03,Zero_ GOTO m008 ; for ( y = 0 ; y < 4 ; y++) CLRF y m004 MOVLW .4 BCF 0x03,RP0 BCF 0x03,RP1 SUBWF y,W BTFSC 0x03,Carry GOTO m007 ; for ( z = 0 ; z < 136 ; z++); CLRF z m005 MOVLW .136 BCF 0x03,RP0 BCF 0x03,RP1 SUBWF z,W BTFSC 0x03,Carry GOTO m006 INCF z,1 GOTO m005 m006 BCF 0x03,RP0 BCF 0x03,RP1 INCF y,1 GOTO m004 m007 BCF 0x03,RP0 BCF 0x03,RP1 DECF x_2,1 INCF x_2,W BTFSC 0x03,Zero_ DECF x_2+1,1 GOTO m003 ;#endif ; ; ;} m008 RETURN ; ;//Long delay ;void delay_s(void) ;{ delay_s ; delay_ms(250); MOVLW .250 BCF 0x03,RP0 BCF 0x03,RP1 MOVWF x_2 CLRF x_2+1 CALL delay_ms ; delay_ms(250); MOVLW .250 BCF 0x03,RP0 BCF 0x03,RP1 MOVWF x_2 CLRF x_2+1 CALL delay_ms ; delay_ms(250); MOVLW .250 BCF 0x03,RP0 BCF 0x03,RP1 MOVWF x_2 CLRF x_2+1 CALL delay_ms ; delay_ms(250); MOVLW .250 BCF 0x03,RP0 BCF 0x03,RP1 MOVWF x_2 CLRF x_2+1 GOTO delay_ms ; FILE D:\Pics\code\16F873\MTA-LCDTest\tstlcd.c ;/* ; 6/27/03 ; Copyright Spark Fun Electronics 2003 ; ; Tests the LCD on the PIC-MTA ; ; For the 28 Pin PIC16F873A-20MHz ; ; Thanks to Olimex for providing the original C code! ; ;*/ ;#define HS_Osc //20MHz operations ; ;#include "d:\Pics\c\16F873.h" // device dependent interrupt definitions ;#include "d:\Pics\code\Delay.c" // Delays. What else? ; ;#pragma config|= 0x3F32 //HS Ocs ; ; ;//Hardware port definitions ;//------------------------------------------------------------------- ; ;#define E RA5 ;#define R_W RA3 ;#define RS RA2 ; ;//Constant definitions ;//--------------------------------------------------------------------- ;#define LED_ON 0 ;#define LED_OFF 1 ;#define OFF 0 ;#define ON 1 ; ;#define DISP_ON 0b00001100 //LCD control constants ;#define DISP_OFF 0b00001000 // ;#define CLR_DISP 0b00000001 // ;#define CUR_HOME 0b00000010 // ;#define ENTRY_INC 0b00000110 // ;#define DD_RAM_ADDR 0b10000000 // ;#define DD_RAM_ADDR2 0b11000000 // ;#define CG_RAM_ADDR 0b01000000 // ; ;//----------------------------------------------------- ;void SEND_CHAR (unsigned char c) ;{ SEND_CHAR BCF 0x03,RP0 BCF 0x03,RP1 MOVWF c ; uns8 data_char; ; ; delay_ms(20); MOVLW .20 MOVWF x_2 CLRF x_2+1 CALL delay_ms ; ; data_char = c & 0b11110000; //get upper nibble MOVLW .240 BCF 0x03,RP0 BCF 0x03,RP1 ANDWF c,W MOVWF data_char ; data_char = data_char >> 4; //set D4-D7 SWAPF data_char,W ANDLW .15 MOVWF data_char ; ; PORTC = data_char; //send data to LCD MOVF data_char,W MOVWF PORTC ; R_W=0; //set LCD to write BCF 0x05,RA3 ; RS=1; //set LCD to data mode BSF 0x05,RA2 ; E=1; //toggle E for LCD BSF 0x05,RA5 ; E=0; BCF 0x05,RA5 ; ; data_char = c & 0b00001111; MOVLW .15 ANDWF c,W MOVWF data_char ; PORTC = data_char; MOVF data_char,W MOVWF PORTC ; R_W=0; //set LCD to write BCF 0x05,RA3 ; RS=1; //set LCD to data mode BSF 0x05,RA2 ; E=1; //toggle E for LCD BSF 0x05,RA5 ; E=0; BCF 0x05,RA5 ;} RETURN ; ;void SEND_CMD (unsigned char d) ;{ SEND_CMD BCF 0x03,RP0 BCF 0x03,RP1 MOVWF d ; uns8 data_char; ; ; delay_ms(10); MOVLW .10 MOVWF x_2 CLRF x_2+1 CALL delay_ms ; ; data_char = d & 0b11110000; //get upper nibble MOVLW .240 BCF 0x03,RP0 BCF 0x03,RP1 ANDWF d,W MOVWF data_char_2 ; data_char = data_char >> 4; //set D4-D7 SWAPF data_char_2,W ANDLW .15 MOVWF data_char_2 ; ; PORTC = data_char; //send data to LCD MOVF data_char_2,W MOVWF PORTC ; R_W=0; //set LCD to write BCF 0x05,RA3 ; RS=0; //set LCD to data mode BCF 0x05,RA2 ; E=1; //toggle E for LCD BSF 0x05,RA5 ; E=0; BCF 0x05,RA5 ; ; data_char = d & 0b00001111; MOVLW .15 ANDWF d,W MOVWF data_char_2 ; PORTC = data_char; MOVF data_char_2,W MOVWF PORTC ; R_W=0; //set LCD to write BCF 0x05,RA3 ; RS=0; //set LCD to data mode BCF 0x05,RA2 ; E=1; //toggle E for LCD BSF 0x05,RA5 ; E=0; BCF 0x05,RA5 ;} RETURN ;//----------------------------------------------------- ; ; ;void main( void ) ; ;{ main ; //PORT DIRECTION INITIALIZATION ; //------------------------------- ; //RBPU=1; //PORTB pull-ups are disabled ; T0CS=1; //Transition on RA4/T0CKI pin BSF 0x03,RP0 BCF 0x03,RP1 BSF 0x81,T0CS ; T0SE=1; //Increment on high-to-low transition on RA4/T0CKI pin BSF 0x81,T0SE ; PSA=1; //Prescaler is assigned to the WDT BSF 0x81,PSA ; TMR0=0; BCF 0x03,RP0 CLRF TMR0 ; ; PORTA=0; CLRF PORTA ; ; ADCON1=0b.0000.1110; //only RA0 is ADC input MOVLW .14 BSF 0x03,RP0 MOVWF ADCON1 ; TRISA= 0b.1101.0001; MOVLW .209 MOVWF TRISA ; ; CHS0=0; //select first chanel BCF 0x03,RP0 BCF 0x1F,CHS0 ; CHS1=0; BCF 0x1F,CHS1 ; CHS2=0; BCF 0x1F,CHS2 ; ; ADON=1; //A/D converter module is operating BSF 0x1F,ADON ; ADFM=1; //Right Justified. 6 most significant bits of ADRESH are read as ‘0’ BSF 0x03,RP0 BSF 0x9F,ADFM ; ; PORTB=0b.0011.1111; MOVLW .63 BCF 0x03,RP0 MOVWF PORTB ; TRISB=0b.1110.1111; //0 = Output, 1 = Input MOVLW .239 BSF 0x03,RP0 MOVWF TRISB ; ; PORTC=0b.0000.0000; BCF 0x03,RP0 CLRF PORTC ; TRISC=0b.1100.0000; //0 = Output, 1 = Input MOVLW .192 BSF 0x03,RP0 MOVWF TRISC ; ;//--------------------init LCD after reset------------- ; ; RS=0; BCF 0x03,RP0 BCF 0x05,RA2 ; R_W=0; BCF 0x05,RA3 ; ; delay_ms(1100); MOVLW .76 MOVWF x_2 MOVLW .4 MOVWF x_2+1 CALL delay_ms ; PORTC=0b.0000.0011; MOVLW .3 BCF 0x03,RP0 BCF 0x03,RP1 MOVWF PORTC ; E=1; BSF 0x05,RA5 ; E=0; BCF 0x05,RA5 ; ; delay_ms(10); MOVLW .10 MOVWF x_2 CLRF x_2+1 CALL delay_ms ; PORTC=0b.0000.0011; MOVLW .3 BCF 0x03,RP0 BCF 0x03,RP1 MOVWF PORTC ; E=1; BSF 0x05,RA5 ; E=0; BCF 0x05,RA5 ; ; delay_ms(10); MOVLW .10 MOVWF x_2 CLRF x_2+1 CALL delay_ms ; PORTC=0b.0000.0011; MOVLW .3 BCF 0x03,RP0 BCF 0x03,RP1 MOVWF PORTC ; E=1; BSF 0x05,RA5 ; E=0; BCF 0x05,RA5 ; ; delay_ms(10); MOVLW .10 MOVWF x_2 CLRF x_2+1 CALL delay_ms ; PORTC=0b.0000.0010; MOVLW .2 BCF 0x03,RP0 BCF 0x03,RP1 MOVWF PORTC ; E=1; BSF 0x05,RA5 ; E=0; BCF 0x05,RA5 ; ; SEND_CMD(DISP_ON); MOVLW .12 CALL SEND_CMD ; SEND_CMD(CLR_DISP); MOVLW .1 CALL SEND_CMD ; ;//Send Text ;//--------------- ; ; SEND_CMD(CLR_DISP); MOVLW .1 CALL SEND_CMD ; SEND_CHAR('G'); MOVLW .71 CALL SEND_CHAR ; SEND_CHAR('o'); MOVLW .111 CALL SEND_CHAR ; SEND_CHAR(' '); MOVLW .32 CALL SEND_CHAR ; SEND_CHAR('O'); MOVLW .79 CALL SEND_CHAR ; SEND_CHAR('l'); MOVLW .108 CALL SEND_CHAR ; SEND_CHAR('i'); MOVLW .105 CALL SEND_CHAR ; SEND_CHAR('m'); MOVLW .109 CALL SEND_CHAR ; SEND_CHAR('e'); MOVLW .101 CALL SEND_CHAR ; SEND_CHAR('x'); MOVLW .120 CALL SEND_CHAR ; SEND_CHAR('!'); MOVLW .33 CALL SEND_CHAR ; SEND_CHAR('L'); MOVLW .76 CALL SEND_CHAR ; SEND_CHAR('C'); MOVLW .67 CALL SEND_CHAR ; SEND_CHAR('D'); MOVLW .68 CALL SEND_CHAR ; SEND_CHAR('-'); MOVLW .45 CALL SEND_CHAR ; SEND_CHAR('O'); MOVLW .79 CALL SEND_CHAR ; SEND_CHAR('K'); MOVLW .75 CALL SEND_CHAR ; delay_ms(10000); MOVLW .16 BCF 0x03,RP0 BCF 0x03,RP1 MOVWF x_2 MOVLW .39 MOVWF x_2+1 CALL delay_ms ; SEND_CMD(CLR_DISP); MOVLW .1 CALL SEND_CMD ;} SLEEP GOTO main ORG 0x2007 DATA 3F32H END ; *** KEY INFO *** ; RAM usage: 6 bytes (6 local), 186 bytes free ; Maximum call level: 2 ; Codepage 0 has 257 word(s) : 12 % ; Codepage 1 has 0 word(s) : 0 % ; Total of 257 code words (6 %) ; P0 12 word(s), 0 %: delay_us ; P0 34 word(s), 1 %: delay_ms ; P0 24 word(s), 1 %: delay_s ; P0 31 word(s), 1 %: SEND_CHAR ; P0 31 word(s), 1 %: SEND_CMD ; P0 124 word(s), 6 %: main