Tuesday, July 8, 2014

BUJJI BUG PART 6


BUJJI BUG part 6 for semi electronic generating DIT and DASH along with sidetone @ 650 Hz .


; BUJJI BUG
; CODE FOR DIT and DASH generation along with sidetone @ 650 Hz.
           list p = 12F683                                      ; Selected 12F683
           #include<p12F683.inc>                         ; Including the headerfile
; In this program we are generating DIT and DASH
; 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 of 80 msec. 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).  During the IDLE state (middle) the GPIO 1(pin no 6 of IC) is sent to LOW(0 Volts).
; To verify we connect an LED from pin  no 6 with a resistor of 2K7.
;..............................................
            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
; Initialising the INPUT and OUTPUT PORTS

            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 2 MHz clock speed to reduce power consumption
            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
pause   MOVLW        0X60                             ; move "FF(HEX)" value into the W register
            MOVWF        COUNT1                      ; presetting COUNT1 register with the value of W register
            MOVLW        0X15                             ; 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
;....................................
ditON  BSF                GPIO,1                          ; when input is low(0 V)make the GPIO pin no 1 as                                                                                                                                         ; high(LED ON)
            MOVLW        0X60                             ; Writing the value 60 (HEX) into W register
            MOVWF        CCPR1L                       ; Passing the value into the CCPR1L register
            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
dashONBSF               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
            GOTO            check                            ; goto check to CHECK the condition

OFF    BCF                GPIO,1                         ; when the input is high(5 V) make the GPIO pin no 1 as                                                                                                                                         ; LOW
            CLRF             CCPR1L                       ; Clear CCPR1L register to remove the sidetone
            GOTO            check                            ; goto check to CHECK the condition and repeat the loop

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 4 usec since clock is 1MHz
;  DECFSZ and GOTO instruction will take 2 instruction cycle each
; 255usec* 8 = 2 mses
; repeating the loop for 20 times => 40 msec of delay.
; NOTE 8: 13 INSTRUCTIONS USED out of 35 INSTRUCTIONS
; 2 GENERAL PURPOSE REGISTER
; 10 SPECIAL FUNCTION REGISTER used out of 38
; 50 bytes of program memory used out of 256 bytes



Here is the HEX code:

:020000040000FA
:100000000301B001B101000083160F168F120F1704
:10001000831285010730990083169F0138308500CF
:100020008316C030920083121214921012150C30F5
:10003000950032286030B0001530B100B00B1E289A
:10004000B10B1E2808008514603093001A2085101B
:1000500093011A20332885146030930033288510CB
:10006000930133280000851E2328051E2B282F28E6
:00000001FF

No comments:

Post a Comment