Thursday, June 26, 2014

BUJJI BUG PART 2


Here we are generating DASH along with side tone  @650 Hz.
To our OLD program we are adding few lines to generate the tone.
AUDIO Amplifer LM386 is included in the circuit to listen the tone in 8 Ohms speaker.
The circuit diagram is given below:

Circuit Diagram

CODE for DASH generation along with side-tone

; BUJJI BUG
;CODE FOR DASH generation along with sidetone
                       list p = 12F683 ; Selected 12F683
                       #include<p12F683.inc> ; Including the headerfile
; We are adding only 10 lines to our OLD program
; Whenever the paddle key GP5 (pin no 2) is pulled-down/connected to the ground,
; The KEY OUT GPIO 1 is sent HIGH and a side tone of 1 KHz @ GP2 (pin no 5)
; otherwise the paddle key is pulled HIGH through a resistor and also send
; KEY OUT to LOW (0 V) @GP1(pin no 6), No sidetone is generated.
;..............................................
                       ORG 0X00 ; Starting address for microcontroller
                       CLRW ; Clearing the W register
                       NOP ; NO operation
                       NOP ; NO operation
                       NOP ; NO operation
                       NOP ; NO operation
                       GOTO           START ; goto start
; Initialising the INPUT and OUTPUT PORTS
START  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
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 by passing the                                                                                                                                 ; "7" into the COMCON0 register
                       BSF             STATUS,RP0 ; Changing to bank 1, because the ANSEL                                                                                                                                 ; TRISIO,T2CON are in bank 1
                       CLRF           ANSEL ; Making the INPUT & OUTPUT as digital by                                                                                                                               ; clearing the ANSEL register                              
                       MOVLW     0X38 ; moving "38" 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
                                                                      ; OUTPUT by passing the value to TRISIO register
;Initialising the PWM for Sidetone
; Below 8 lines are added extra to OUR OLD PROGRAM
                       MOVLW     0XC0 ; Writing the value "CO(HEX)" into the W register
                       MOVWF     PR2 ; passing the value into PR2 register.
                       BCF           STATUS,RP0 ; bank zero is selected
                       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
                       BCF           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
;....................................
dashON         BSF      GPIO,1 ; when input is low(ZERO)make the GPIO pin no                                                                                                                       ;1 as high(LED IS ON)
; TWO more lines are added here to switch ON the PWM.
;.....................................................
                       MOVLW     0X62
                       MOVWF     CCPR1L ; PWM will be 50% by passing the value "62(HEX)" into the CCPR1L register.
;...................................................
                       GOTO          run ; goto run & check the condition and repeat the loop ever
dashOFF BCF            GPIO,1 ; when the input is high make the GPIO pin no 1                                                                                                                         ;as LOW(LED iS OFF)
; one more line is added here to SWITCH OFF the PWM.
;....................................................
                       CLRF          CCPR1L ; PWM will become ZERO by passing the value                                    
                       GOTO         run ; goto run to check the condition and repeat the loop                                                                                                                   ; "0" to the CCPR1L register
;...................................................
; This is the OLD CODE only
begin NOP ; NO operation
run BTFSS         GPIO,5 ; checking the input status of the GP5( pin no 2 of IC)
                       GOTO         dashON                 ; if it is Clear(ZERO) goto dashON otherwise
                       GOTO         dashOFF ; goto dash
                       END ; end of the program




; NOTE 1: This program is running with internal 2MHZ clock
; Note 2; We are using 4 NOP (No OPeration) instructions after the ORG 0X00 avoiding the risk of interrupts
; NOTE 3: program memory will begin from the address 0X00
; NOTE 4: we can configure the internal clock to work at various frequencies
; OSCCON register is used to select the frequencies
; NOTE 5: ANSEL Register is used to select the analog I/O.
; By clearing it we are making all pins as DIGITAL IO ports
; NOTE 6: we are not using any comparators in our program
; so we are disabling them by passing the value "7" into CMCON0
; NOTE 7: Three register are required to enable the PWM in 12F683
; 1. TMR2 is used to prescale the Fosc. here we are pre scalling it to 1:4 ratio
; 2. PR2 is used to select the period of the PWM
; PR2 = PWM period/(4*Tosc* TMR2prescalar)-1
; 3. CCPR1L register is used to assign the duty cycle of PWM
; we are using 8 bit PWM => 62(HEX) is passing into the register to get 50% PWM.
; So PWM is ON.
; To switch OFF PWM we assign duty cycle 0% by resetting CCPR1L.

Here is the HEX code

:020000040000FA
:100000000301000000000000000006288501073001
:10001000990083169F0138308500831213288514B8
:0E0020001428851014280000851E0F281128B2
:00000001FF

1 comment:

  1. Can you please write about the development used for this project (i.e. Assembler and Programmer)?
    73
    Praveen VU3CKP

    ReplyDelete