;****************************************************************************************** ; Project : ; Program Name : ; Programer : ; Create date : Version 1.0 H30.11.09 ; History : ; Language : mpasm v5.72 ;****************************************************************************************** ; Description (PIC16F636 specific settings) ; 1.Program memory map ; 1) On Chip Program memory ; Page 0 : 0005h - 07ffh ; Page 1 : 0800h - 0fffh ; 2) Data memory ; Bank 0 : RP1:RP0 00 / General Purpose Register 20h - 7fh (96 Bytes) ; Bank 1 : RP1:RP0 01 / General Purpose Register a0h - efh (80 Bytes) ; Bank 2 : RP1:RP0 10 / General Purpose Register 120h - 16fh (80 Bytes) ; Bank 3 : RP1:RP0 11 / General Purpose Register 1a0h - 1efh (80 Bytes) ; 2.Oscillator configuration ; Internal Oscillator 8MHz ; 3.Port Mapping ; PORTA(0-5) : ; PORTC(0-5) : ;****************************************************************************************** LIST P=PIC16F636,ST=OFF,R=DEC INCLUDE "p16f636.inc" __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF & _WUREN_OFF SETBNK0 MACRO ; This macro sets BANK of memory to 0 BCF STATUS,RP1 BCF STATUS,RP0 ENDM SETBNK1 MACRO ; This macro sets BANK of memory to 1 BCF STATUS,RP1 BSF STATUS,RP0 ENDM SETBNK2 MACRO ; This macro sets BANK of memory to 2 BSF STATUS,RP1 BCF STATUS,RP0 ENDM SETBNK3 MACRO ; This macro sets BANK of memory to 3 BSF STATUS,RP1 BSF STATUS,RP0 ENDM PUTUART MACRO #U_CHAR MOVLW #U_CHAR CALL UARTDX ENDM ;SELBNK MACRO #BANK_NO ; MOVLW #BANK_NO ; MOVWF BSR ; ENDM ; Temporary variable TMP0 EQU 20H ; temporary TMP1 EQU 21H ; temporary TMP2 EQU 22H ; temporary ; Variables to use with UART (Recive) IODAT EQU 23H ; Temporary to use with UART function RECWAT EQU 24H ; Temporary to use with UART function RECLP EQU 25H ; Temporary to use with UART function; ; Variables to use with UART (Transmit) ; This memory area is defined in the shared area because transmission and reception do not move at the same time ;IODAT EQU 23H ; Temporary to use with UART function SENDWAT EQU 24H ; Temporary to use with UART function SENDLP EQU 25H ; Temporary to use with UART function ADR EQU 20H ; Adress DAT EQU 21H ; Data LP EQU 22H CNT0 EQU 23H CNT1 EQU 24H CNT2 EQU 25H DAT0 EQU 26H DAT1 EQU 27H ORG 0 ; Reset Vector GOTO START ORG 4 ; Interrupt Vector GOTO START START ; ******************************* ; 1.Initalized ; ******************************* ; (1)Define Oscillator (Internal Oscillator 8MHz) SETBNK1 MOVLW B'01110001' MOVWF OSCCON ;Bank1 ; (2)Define I/O Port ; 2-1)Set all ports to digital SETBNK0 MOVLW B'00000111' MOVWF CMCON0 ;Bank0 ; 2-2)Initial value is set for all port SETBNK0 CLRF PORTA ;Bank0 CLRF PORTC ;Bank0 MOVLW B'00000001' MOVWF PORTC ; 2-3)Set port direction SETBNK1 MOVLW B'11111111' MOVWF TRISA ;Bank1 MOVLW B'11111110' MOVWF TRISC ;Bank1 ; ******************************* ; 2.Program main ; ******************************* SETBNK0 CALL DEM02 MAIN CALL UARRDX CALL UARTDX GOTO MAIN ;********************************************************************************************************** ; Function Name : UARRDX ; Title : This function is a receiving program using UART. ; Input : ; Output : W-Reg ; Description : 9600BPS OSC;8.000MHz PORTA[2] ;********************************************************************************************************** UARRDX ; (0)Clear I/O Data variable CLRF IODAT ; (1)Wait for reception state BTFSC PORTA,2 GOTO $-1 ; (2)Wait 1/2 cycle MOVLW H'21' ; 9600BPS,OSC;8MHz MOVWF RECWAT DECFSZ RECWAT,F GOTO $-1 ; (3)Loop to receive 8 bits MOVLW 8 MOVWF RECLP NOP UARRDX2 MOVLW H'42' ; 9600BPS,OSC;8MHz MOVWF RECWAT UARRDX3 DECFSZ RECWAT,F GOTO UARRDX3 NOP BTFSS PORTA,2 ; If the bit is H, do not execute next BCF STATUS,C ; BTFSC PORTA,2 ; If the bit is L, do not execute next BSF STATUS,C RRF IODAT,F ; Shift variable one bit to the right DECFSZ RECLP,F GOTO UARRDX2 NOP NOP ; (4)Copy W-register MOVFW IODAT ; RETURN ;********************************************************************************************************** ; Function Name : UARTDX ; Title : This function is a transmitting program using UART. ; Input : W-Reg ; Output : ; Description : 9600BPS OSC;8.000MHz PORTC[0] ;********************************************************************************************************** UARTDX MOVWF IODAT ; (1)Set to send status UARTDX0 BCF PORTC,0 MOVLW H'42' ; 9600BPS,OSC;8MHz MOVWF SENDWAT DECFSZ SENDWAT,F GOTO $-1 ; ; (2)A loop that transmits 8-bit data MOVLW 8 ; Send 8-bit data MOVWF SENDLP NOP UARTDX2 RRF IODAT,F NOP BTFSS STATUS,C ; If the bit is H, do not execute next BCF PORTC,0 BTFSC STATUS,C ; If the bit is L, do not execute next BSF PORTC,0 MOVLW H'42' ; Wait timer(9600BPS,OSC;8MHz) MOVWF SENDWAT DECFSZ SENDWAT,F GOTO $-1 DECFSZ SENDLP,F GOTO UARTDX2 ; (3)Return transmission status BSF PORTC,0 ; Set the bit to H ; (4)Wait a while after sending MOVLW H'64' MOVWF SENDWAT DECFSZ SENDWAT,F GOTO $-1 RETURN ;********************************************************************************************************** ; Function Name : DEM01 ; Title : This function flashes the LED at 1 second intervals when the system frequency is 8 MHz. ; Input : ; Output : ;********************************************************************************************************** DEM01 ; ******************************* ; 1.Main loop ; ******************************* SETBNK0 MOVLW H'FF' MOVWF PORTC CALL DEM01WT MOVLW H'00' MOVWF PORTC CALL DEM01WT GOTO DEM01 ;********************************************************************************************************** ; Function Name : DEM01WT ; Title : This function waits for 1 second when the system frequency is 8 MHz. ; Input : ; Output : ;********************************************************************************************************** DEM01WT MOVLW H'C8' MOVWF TMP2 DEM01W2 MOVLW H'64' MOVWF TMP1 DEM01W1 MOVLW H'0A' MOVWF TMP0 DEM01W0 NOP NOP NOP NOP NOP NOP NOP DECFSZ TMP0,F GOTO DEM01W0 DECFSZ TMP1,F GOTO DEM01W1 DECFSZ TMP2,F GOTO DEM01W2 RETURN ;********************************************************************************************************** ; Function Name : DEM02 ; Title : This function outputs start message to UART ; Input : ; Output : ;********************************************************************************************************** DEM02 PUTUART ' ' PUTUART 'P' PUTUART 'I' PUTUART 'C' PUTUART '1' PUTUART '6' PUTUART 'F' PUTUART '6' PUTUART '3' PUTUART '6' PUTUART ' ' PUTUART 'C' PUTUART 'o' PUTUART 'n' PUTUART 'n' PUTUART 'e' PUTUART 'c' PUTUART 't' PUTUART 'e' PUTUART 'd' PUTUART ' ' PUTUART 'O' PUTUART 'K' PUTUART '>' PUTUART ' ' RETURN END