; PIC16C61/71 demostration program ; M P Roberts 12/1/97 NOLIST ;========================================================================== ; ; Verify Processor ; ;========================================================================== IFNDEF __16C71 MESSG "Processor-header file mismatch. Verify selected processor." ENDIF ;========================================================================== ; ; Register Definitions ; ;========================================================================== W EQU H'0000' F EQU H'0001' ;----- Register Files------------------------------------------------------ INDF EQU H'0000' TMR0 EQU H'0001' PCL EQU H'0002' STATUS EQU H'0003' FSR EQU H'0004' PORTA EQU H'0005' PORTB EQU H'0006' ADCON0 EQU H'0008' ADRES EQU H'0009' PCLATH EQU H'000A' INTCON EQU H'000B' OPTION_REG EQU H'0001' TRISA EQU H'0005' TRISB EQU H'0006' ADCON1 EQU H'0008' ;----- STATUS Bits -------------------------------------------------------- IRP EQU H'0007' RP1 EQU H'0006' RP0 EQU H'0005' NOT_TO EQU H'0004' NOT_PD EQU H'0003' Z EQU H'0002' DC EQU H'0001' C EQU H'0000' ;----- INTCON Bits -------------------------------------------------------- GIE EQU H'0007' ADIE EQU H'0006' T0IE EQU H'0005' INTE EQU H'0004' RBIE EQU H'0003' T0IF EQU H'0002' INTF EQU H'0001' RBIF EQU H'0000' ;----- OPTION Bits -------------------------------------------------------- NOT_RBPU EQU H'0007' INTEDG EQU H'0006' T0CS EQU H'0005' T0SE EQU H'0004' PSA EQU H'0003' PS2 EQU H'0002' PS1 EQU H'0001' PS0 EQU H'0000' ;========================================================================== ; ; RAM Definition ; ;========================================================================== __MAXRAM H'AF' __BADRAM H'07', H'30'-H'7F', H'87' ;========================================================================== ; ; Configuration Bits ; ;========================================================================== _CP_ON EQU H'3FEF' _CP_OFF EQU H'3FFF' _PWRTE_ON EQU H'3FFF' _PWRTE_OFF EQU H'3FF7' _WDT_ON EQU H'3FFF' _WDT_OFF EQU H'3FFB' _LP_OSC EQU H'3FFC' _XT_OSC EQU H'3FFD' _HS_OSC EQU H'3FFE' _RC_OSC EQU H'3FFF' LIST ; PIC16C71 is the target processor __CONFIG _CP_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC ; data register definitions temp equ h'C' ;temporary register temp2 equ h'D' ;temporary register cnt equ h'E' ;serial bit counter csec equ h'F' ;1/100 second counter serpin equ h'2' ;serial output pin on PORTA org 0 goto Start org 4 ;interrupt routine bcf INTCON,T0IF ;clear interrupt flag ;your code here movlw h'80' call COUT ;Display RAM address to 0 movlw 'H' call DOUT movlw 'e' call DOUT movlw 'l' call DOUT movlw 'l' call DOUT movlw 'o' call DOUT movlw ' ' call DOUT movlw 'F' call DOUT movlw 'r' call DOUT movlw 'e' call DOUT movlw 'd' call DOUT incf csec,F ;increment seconds counter movlw d'100' subwf csec,0 ;w=csec-100 btfsc STATUS,Z ;skip if csec<>100 clrf csec ;reset csec=0 movf csec,F btfsc STATUS,Z ;skip if csec <>0 call HELLO decf csec,W ;w=csec-1 btfsc STATUS,Z ;skip if csec <>1 call FRED retfie ;return from interrupt HELLO movlw 'H' call SERIAL movlw 'e' call SERIAL movlw 'l' call SERIAL movlw 'l' call SERIAL movlw 'o' call SERIAL return FRED movlw ' ' call SERIAL movlw 'F' call SERIAL movlw 'r' call SERIAL movlw 'e' call SERIAL movlw 'd' call SERIAL return ; start of main programme ; set up system Start bcf STATUS,RP0 ;bank 0 movlw b'10100000' movwf INTCON ;interupts from TMR0 only clrf PORTB ;port b all off clrf PORTA ;port a all off bsf STATUS,RP0 ;bank 1 movlw b'00000100' movwf OPTION_REG ;set option, pulup, /32 clk clrf TRISB ;portb all output movlw b'00000011' movwf ADCON1 ;porta digital only movlw b'00011000' movwf TRISA ;porta bits0-2 out 3,4,in bcf STATUS,RP0 ;bank 0 clrf csec ;seconds counter to 0 ; set up display movlw h'38' call COUT ;2 lines clrf temp2 movlw d'6' ;delay for 4100us movwf temp st1 decfsz temp2,F goto st1 decfsz temp,F goto st1 movlw h'38' call COUT ;2 lines movlw d'20' ;delay for 60us movwf temp st2 decfsz temp,F goto st2 movlw h'38' call COUT ;2 lines movlw h'38' call COUT ;2 lines movlw h'06' call COUT ;entry mode cursor right movlw h'0C' call COUT ;display on,no cursor,no blink movlw h'01' call COUT ;clear + address 0 ; wait 1600uS (not needed wait interrupt) clrf temp2 movlw d'2' ;delay for 1600us movwf temp st3 decfsz temp2,F goto st3 ;3 x256 =768 decfsz temp,F goto st3 ; operating loop loop nop goto loop ; display output subroutines COUT bcf PORTA,0 ;RA0=0 control data for display goto out1 DOUT bsf PORTA,0 ;RA0=1 data to display out1 movwf PORTB ;portb=w bsf PORTA,1 ;enable bcf PORTA,1 ;disable ; wait > 40uS movlw d'13' ;w=13 movwf temp ;temp=13 out2 decfsz temp,F ;dec skip zero goto out2 return ;sub to output w as serial info SERIAL movwf temp ;temp=w movlw 8 movwf cnt ;cnt=8 bcf PORTA,serpin ;start bit goto ser1 ser1 call SDEL rrf temp,F btfsc STATUS,C bsf PORTA,serpin btfss STATUS,C bcf PORTA,serpin decfsz cnt,F goto ser1 goto ser2 ser2 call SDEL bsf PORTA,serpin ;stop bit call SDEL call SDEL return ;delay for serial(3.2768/4/9600) SDEL movlw d'24' movwf temp2 sdel1 decfsz temp2,F goto sdel1 return END