; ; The purpose of this program is to blink the letters ; "F" "S" "C" in Morse code. ; Morse code consists of ; dots, which are short blinks; ; dashes, which are long blinks, three times as long as a dot; ; and spacings, which are periods in which the light is off. ; spacings come in various lengths: ; Within a letter, dots and dashes are separated by a ; spacing which is the same length as a dot. ; letters are separated by a spacing the same length as a dash. ; And words are separated by a spacing five times as long as a dot. ; ; The code: (More or less. It's a long time since Boy Scouts) ; A .- * B -... * C -.-. * D -.. ; E . * F ..-. * G --. * H .... ; I .-. * J .--- * K -.- * L .-.. ; M -- * N -. * O --- * P .--. ; Q --.- * R .-. * S ... * T - ; U ..- * V ...- * W .-- * X -..- ; Y -.-- * Z --.. ; ; ; This is a program for a PIC microprocessor. ; It expects GPIO bit2 to control an LED, ; when GPIO bit 2 is set to one, the LED should light ; when GPIO bit 2 is set to zero, the LED should turn off. ; Check the pin diagram to see which pin on the chip ; corresponds to GPIO bit 2. ;/ list p=12F683 ; list directive to define processor #include ;configuration word for 12f683 __CONFIG _WDT_OFF & _INTOSC ; watchdog timer off, ; internal oscillator ERRORLEVEL -302; ;omit the out-of-bank message org 0 ; reset vector Start: goto main org 4 ; interrupt vector retfie ; do nothing main: banksel TRISIO ;select bank 1, where TRISIO is stored. movlw 0 ;set GP0-GP5 all outputs. movwf TRISIO banksel GPIO ;select bank 0, to use GPIO bcf GPIO,2; ;; turn off LED loop: call letterF call S call letterC call spacing goto loop ; The following routines implement (part of) Morse code. dotTime: call delay; ;; wait a bit return dot: bsf GPIO,2; ;; turn on LED call dotTime; ;; wait a bit bcf GPIO,2; ;; turn off LED call dotTime; ;; wait a bit return dash: bsf GPIO,2; ;; turn on LED call dotTime call dotTime call dot ;; wait a bit return ; ; this spacing routine doesn't neet to be called between dots and dashes, ; because those routines end in an unlit delay of ; one dot time. ; called at the end of letters, it need only delay two dot times, ; since there was already a delay of one dot time after the ; most recent dot or dash. ; When called between letters, the explicit call to spacing, ; plus the call at the end of the last letter, ; (along with the delay at the end of the letter's last dot or dash) ; results in a total delay of five dot times. ; spacing: call dotTime call dotTime return ; These letter routines each produce a single letter ; The code for C is dash dot dash dot (-.-.) letterC: call dash ; call the dash routine call dot ; follow it with the dot routine call dash ; another dash call dot ; the final dot call spacing return ; The code for E is one dot. Follow each letter with a spacing E: call dot call spacing return ; The code for F is ..-. letterF: call dot call dot call dash call dot call spacing return ; This routine for S puts out two dots, then ; finishes up by invoking the E routine, which puts ; out a dot and then spacings ;/ S: call dot call dot call E return ; This routine for T T: call dash call spacing return ;define program variables. These happen to be in bank 0 i equ 0x20 j equ 0x21 k equ 0x22 delay: ;delays~ 1 second on a 4MHz clock movlw 5 movwf i ;uses a triply nested loop topi: clrf j topj: clrf k topk: incfsz k,1 ;count to 256 goto topk ;inner loop is 3 cycles incfsz j,1 goto topj decfsz i,1 goto topi return end