; morse code spotlight ; Norbert Doerry ; Jan 2012 ; ; Code for final host PIC 12F683 ; ; GP2 is the actual output ; GP5 toggles for each time increment ; GP4 toggles for each character (but doesn't work properly) ; ; Based on Template File list p=12F683 ; list directive to define processor #include ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file ; __CONFIG _FCMEN_ON & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTOSCIO __CONFIG _FCMEN_ON & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT ; '__CONFIG' directive is used to embed configuration word within .asm file. ; The lables following the directive are located in the respective .inc file. ; See data sheet for additional information on configuration word settings. ;***** VARIABLE DEFINITIONS w_temp EQU 0x7E ; variable used for context saving status_temp EQU 0x7F ; variable used for context saving Delay1 EQU 0x7D ; Variable for delay loop Delay2 EQU 0x7C ; variable for delay loop MC_char EQU 0x7B ; used to hold character code (leading 1, followed by 1 for dash, 0 for dot) MC_ctr EQU 0x7A ; used as a counter for which bit is being examined in MC_char ;********************************************************************** ORG 0x000 ; processor reset vector goto start ; go to beginning of program ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register ; isr code can go here or be located as a call subroutine elsewhere movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt ; initialize eeprom locations ; ORG 0x2100 ; DE 0x00, 0x01, 0x02, 0x03 ; END ; directive 'end of program' PGM CODE 0x0100 start: BANKSEL GPIO ; CLRF GPIO ;Init GPIO BANKSEL CMCON0 ; disable comparators BSF CMCON0, CM0 BSF CMCON0, CM1 BSF CMCON0, CM2 BANKSEL ANSEL ; BCF ANSEL, GP2 ; digital I/O BCF ANSEL, GP4 BCF ANSEL, GP5 BANKSEL TRISIO BCF TRISIO, GP2 ; set as output BCF TRISIO, GP4 BCF TRISIO, GP5 CALL DelayLoop message_loop: MOVLW 0x0E ; letter G in MC CALL Outchar MOVLW 0x0F ; letter O in MC CALL Outchar MOVLW 0x00 ; space in MC CALL Outchar MOVLW 0x06 ; letter N in MC CALL Outchar MOVLW 0x05 ; letter A in MC CALL Outchar MOVLW 0x11 ; letter V in MC CALL Outchar MOVLW 0x1B ; letter Y in MC CALL Outchar MOVLW 0x00 ; space in MC CALL Outchar MOVLW 0x00 ; space in MC CALL Outchar GOTO message_loop DelayLoop: banksel Delay1 CLRF Delay1 banksel Delay2 MOVLW 0xF0 movwf Delay2 DelayLoop1: banksel Delay1 DECFSZ Delay1,f GOTO DelayLoop1 banksel Delay2 DECFSZ Delay2,f GOTO DelayLoop1 ; ; Toggle GP5 for each time increment ; BANKSEL GPIO BTFSC GPIO, GP5 GOTO clear_gp5 BSF GPIO, GP5 RETURN clear_gp5: BCF GPIO, GP5 return Outchar: banksel MC_char movwf MC_char ; ; the following is intended to toggle GP4 each time a character is processed ; not sure why, but it is only flashing quickly for each character. ; something is resetting it. ; BANKSEL GPIO BTFSC GPIO, GP4 GOTO clear_gp4 BSF GPIO, GP4 GOTO end_gp4 clear_gp4: BCF GPIO, GP4 end_gp4: ; find the leading 1, if don't find it then a space banksel MC_ctr movlw 0x08 movwf MC_ctr Outchar1: banksel MC_char rlf MC_char, 1 bc Outchar2 banksel MC_ctr decfsz MC_ctr,1 goto Outchar1 ; didn't find the leading 1 goto Outchar_space ; no leading 1, this is a space Outchar2: ; found the leading 1, look at next bits until all gone BANKSEL MC_ctr decfsz MC_ctr,1 goto Outchar3 Outchar_end: BANKSEL GPIO BCF GPIO, GP2 ; Turn off LED GP2 CALL DelayLoop CALL DelayLoop return Outchar3: ; check if dot or dash BANKSEL MC_char rlf MC_char, 1 bc Outchar4 ; see if a dash, ; its a dot BANKSEL GPIO BSF GPIO, GP2 ; turn on LED GP2 CALL DelayLoop BANKSEL GPIO BCF GPIO, GP2 ; Turn off LED GP2 CALL DelayLoop GOTO Outchar2 ; get the next dot or dash Outchar4: ; its a dash BANKSEL GPIO BSF GPIO, GP2 ; turn on LED GP2 CALL DelayLoop CALL DelayLoop CALL DelayLoop BANKSEL GPIO BCF GPIO, GP2 ; Turn off LED GP2 CALL DelayLoop GOTO Outchar2 Outchar_space: ; turn off the LED for 7 time units BANKSEL GPIO BCF GPIO, GP2 ; Turn off LED GP2 CALL DelayLoop CALL DelayLoop CALL DelayLoop CALL DelayLoop CALL DelayLoop CALL DelayLoop CALL DelayLoop return END