Friday, July 11, 2014

BUJJI BUG PART 6A

BUJJI KEYER for automatic generation of DIT and DASH.

BUJJI BUG is different from BUJJI KEYER.
In Bujji Bug DASH's are generated manually whereas in KEYER both DIT and DASH's are generated automatically.
; BUJJI KEYER
; CODE FOR automatic DIT and DASH generation along with sidetone @650Hz
; Here GPIO 5 (pin no. 2 of IC) and GPIO 4 (pin no 3 of IC) is pulled to HIGH by the resistor
; home made paddle is connected to this pins, 
; when it is pulled to one side (right side) The KEY OUT GPIO 1 (pin no 6 of IC) is sent to HIGH (5 Volts)
; and LOW (0 V) with a delay. It will continue till the paddle is released. 
; when the paddle is pulled to otherside (left side) the KEY OUT GPIO 1(pin no 6 of IC) is sent to HIGH(5 Volts).
; and LOW (0 V) with a delay of 3XDIT (3 times of the dit).
; During the IDLE state (middle) the GPIO 1(pin no 6 of IC) is sent to LOW(0 Volts) without any sidetone.
; To verify we connect an LED from pin  no 6 with a resistor of 2K7.
;...........................................................

           list p = 12F683              ; Selected 12F683 
           #include<p12F683.inc>        ; Includeing the headerfile

; These general purpose registers used in the delay function.

            CBLOCK       0X30           ; Starting Address/location of the registers
            COUNT1                      ; Location 0X30 is referred as COUNT1 in the program
            COUNT2                      ; Location 0X31 is referred as COUNT2 in the program
            ENDC                        ; end the block
;...................................................................................................................
            ORG          0X00           ; Starting address for microcontroller program
            CLRW                        ; Clearing the W register
            CLRF         COUNT1         ; Clearing the COUNT1 register at power ON time
            CLRF         COUNT2         ; Clearing the COUNT2 register at power ON time
            NOP                         ; NO operation
;           NOP                         ; This location is reserved for INTERRUPT and 
                                        ; hence we always code the fifth line as NOP
;..................................................................................................................
; Setting the clock frequency 
            BSF          STATUS,RP0     ; Selecting the bank 1
            BSF          OSCCON,IRCF0   ; Internal Oscillator frequency can be configured by
            BCF          OSCCON,IRCF1   ; enabling the appropriate registers in the OSCCON register
            BSF          OSCCON,IRCF2   ; IRCF0, IRCF1,IRCF2 are the bits to select the various frequency ranges
                                        ; Here we have configured 2MHz clock speed to reduce power consumption 
;...................................................................................................................
;Setting the input and output ports
;...................................................................................................................
            BCF          STATUS,RP0     ; changing to bank 0
            CLRF         GPIO           ; Clearing the INPUT OUTPUT port registers
            MOVLW        0X07           ; Moving the "7(HEX)" into the W register
            MOVWF        CMCON0         ; Comparators are disabled
            BSF          STATUS,RP0     ; Changing to bank 1, because the ANSEL,TRISIO,T2CON are in bank 1
            CLRF         ANSEL          ; please see BUJJI BUG part 1  
            MOVLW        0X38           ; moving "38(HEX)" value into W register
            MOVWF        TRISIO         ; making the GP3,GP4,GP5(pin no 5 of IC)as a input and
                                        ; GP0,GP1(pin no 6 of IC),GP2,OUTPUTS
            BSF          STATUS,RP0     ; Changing to bank 0
;...................................................................................................................
; Initialising the PWM for sidetone
;...................................................................................................................
            MOVLW        0XC0           ; writing the value C0(HEX) into the W register
            MOVWF        PR2            ; passing the value into PR2 register
            BCF          STATUS,RP0     ; selecting the bank 0
            BSF          T2CON,T2CKPS0  ; TIMER2 prescalar value is initiaizing as 1:4 ratio by setting T2CKPS0 bit   
            BCF          T2CON,T2CKPS1  ; and clearing the T2CKPS1 bit in the T2CON register
            BSF          T2CON,TMR2ON   ; Enabling the TIMER2 by setting the bit TMR2ON
            MOVLW        0X0C           ; Writing the value "12" into the W register
            MOVWF        CCP1CON        ; Configuring the GP3 (pin no 5) as PWM OUTPUT
;...................................................................................................................
            GOTO         begin          ; Goto begin
;...................................................................................................................
;delay loop
;...................................................................................................................
pause       MOVLW        0XFF           ; move "FF(HEX)" value into the W register
            MOVWF        COUNT1         ; presetting COUNT1 register with the value of W register
            MOVLW        0X30           ; move the "80(HEX)" value int the W register 
            MOVWF        COUNT2         ; presetting COUNT2 register with the value of W register
wait        DECFSZ       COUNT1,F       ; Decrement and check whether count1 register is zero, if zero skip next instruction
            GOTO         wait           ;  otherwise go to wait
            DECFSZ       COUNT2,F       ; Decrement and check whether count2 register is zero, if zero skip next instruction
            GOTO         wait           ; go to wait
            RETURN                      ; going back to the program code
                                        ; every CALL function should end with RETURN
;.....................................................................................................................
;Loop for DIT ON
;.....................................................................................................................
ditON       BSF          GPIO,1         ; when input is low(0 V)make the GPIO pin no 1 as high(LED IS ON)
            MOVLW        0X60           ; Writing the value 60 (HEX) into W register
            MOVWF        CCPR1L         ; Passing the value into the CCPR1L register to SWITCH ON the tone
            CALL         pause          ; Call delay
            BCF          GPIO,1         ; Clearing the GP1 pin (0 V) (LED is OFF)
            CLRF         CCPR1L         ; Clear the CCPR1L register to remove the sidetone
            CALL         pause          ; Call delay
;.....................................................................................................................
            GOTO         check          ; goto check to CHECK the condition and repeat the loop forever
;.....................................................................................................................
;Loop for DASH ON
;.....................................................................................................................
dashON      BSF          GPIO,1         ; make the GPIO 1 (pin no 6 of IC) to HIGH
            MOVLW        0X60           ; Writing the value 60 (HEX) into W register
            MOVWF        CCPR1L         ; Passing the value into the CCPR1L register to SWITCH ON the tone
            CALL         pause          ; call delay
            CALL         pause          ; call delay
            CALL         pause          ; call delay
            BCF          GPIO,1         ; Clearing the GP1 pin (0 V) (LED is OFF)
            CLRF         CCPR1L         ; Clearing the CCPR1L register to SWITCH OFF the side tone
            CALL         pause
;....................................................................................................................
            GOTO         check          ; goto check to CHECK the condition
;....................................................................................................................
;Loop for OFF
;....................................................................................................................

OFF         BCF          GPIO,1         ; when the input is high(5 V) make the GPIO pin no 1 as LOW(LED iS OFF)
            CLRF         CCPR1L         ; Clear CCPR1L register to remove the sidetone
;....................................................................................................................
            GOTO         check          ; goto check to CHECK the condition and repeat the loop 
;....................................................................................................................
;Main function
;....................................................................................................................
begin       NOP                         ; NO Operation
check       BTFSS        GPIO,5         ; checking the input status of the GP5( pin no 2 of IC)
            GOTO         ditON          ; if it is Clear(ZERO) goto dashON otherwise
            BTFSS        GPIO,4         ; checking the input status of the GP6( pin no 3 of IC)
            GOTO         dashON         ; goto dashON
            GOTO         OFF            ; goto OFF
            END                         ; end of the program
;...................................................................................................................   
 
  
  
; NOTE 1: This program is running with 2MHZ clock
; NOTE 2: program memory will begin from the address 0X00
; NOTE 3: we can configure the internal clock to work at various frequencies
;   OSCCON register is used to select the frequencies
; NOTE 4: ANSEL Register is used to select the analog I/O.
;   By clearing it we are making all pins as DIGITAL IO ports
; NOTE 5: we are not using any comparators in our program 
;   so we are disabling them by passing the value "7" into CMCON0
; NOTE 6: The value in CCPR1L is used to set the DUTY CYCLE of PWM OUT OF PR2 value.
; NOTE 7: one instruction cycle consists of 4 oscillations, to execute one instruction
;   it wil take 2 usec since clock is 2 MHz
;   DECFSZ and GOTO instruction will take 2 instruction cycle each
;   255usec* 8 = 2 mses
;    repeating the loop for 48 times => 96 msec of delay.
; NOTE 8: 11 INSTRUCTIONS USED out of 35 INSTRUCTIONS
;   2 GENERAL PURPOSE REGISTER
;   10 SPECIAL FUNCTION REGISTER used out of 38
;   62 bytes of program memory used out of 256bytes.
Here is the HEX file:
:020000040000FA :100000000301B001B101000083160F168F120F1704 :10001000831285010730990083169F0138308500CF :100020008316C030920083121214921012150C30F5 :1000300095003828FF30B0003030B100B00B1E28DA :10004000B10B1E2808008514603093001A2085101B :1000500093011A2039288514603093001A201A2041 :100060001A20851093011A20392885109301392808 :0C0070000000851E2328051E2B283528C3 :00000001FF

No comments:

Post a Comment