Here we are generating DIT.
The KEY OUT is sent HIGH and LOW with a delay of 250 msec when theKEY IN is grounded,
KEY OUT is sent LOW when the KEY IN is HIGH.
To check the OUTPUT we connected LED to the GP1 (pin no 6 of IC).
For circuit see part 1.
; BUJJI BUG
; CODE FOR DIT generation.
list p = 12F683 ; Selected 12F683
#include<p12F683.inc> ; Includeing the headerfile
; In this program we are generating DIT
; here GPIO 5 (pin no. 2) is pulled to HIGH by the resistor
; external paddle is connected to this pin,
; when it is pulled-down/grounded (pin no.2) The KEY OUT GPIO 1 is send to HIGH (5 volts)
; and LOW (0 V) with a delay of 250 msec. It will continue till the paddle is released.
; Otherwise KEY OUT will be in the LOW state(0 volts).
; To verify we connect an LED from pin no 6 with a resistor 2K7.
;..............................................
; Till now we have not used any RAM which is also called GENERAL PURPOSE REGISTER
; in microprocessor/microcontroller world
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
; 2MHz 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
BCF STATUS,RP0 ; Changing to bank 0
GOTO begin ; Goto begin
pause MOVLW 0XFF ; move "FF(HEX)" value into the W register
MOVWF COUNT1 ; presetting COUNT1 register with the value of W register
MOVLW 0X80 ; 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 IS ON)
CALL pause ; Call delay
BCF GPIO,1 ; Clearing the GP1 pin (0 V) (LED is OFF)
CALL pause ; Call delay
GOTO check ; goto run to check the condition and repeat the loop ; forever
ditOFF BCF GPIO,1 ; when the input is high(5 V) make the GPIO pin no 1 ; as LOW(LED iS OFF)
GOTO check ; goto run to check the condition and repeat the loop
begin NOP
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
GOTO ditOFF ; goto dash
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: one instruction cycle consists of 4 oscillations, to execute one instruction
; it wil take 2 usec since clock is 2MHz
; DECFSZ and GOTO instruction will take 2 instruction cycle each
; 255usec* 4 = 2 mses
; repeating the loop for 128 times => 256 msec of delay.
The KEY OUT is sent HIGH and LOW with a delay of 250 msec when theKEY IN is grounded,
KEY OUT is sent LOW when the KEY IN is HIGH.
To check the OUTPUT we connected LED to the GP1 (pin no 6 of IC).
For circuit see part 1.
; BUJJI BUG
; CODE FOR DIT generation.
list p = 12F683 ; Selected 12F683
#include<p12F683.inc> ; Includeing the headerfile
; In this program we are generating DIT
; here GPIO 5 (pin no. 2) is pulled to HIGH by the resistor
; external paddle is connected to this pin,
; when it is pulled-down/grounded (pin no.2) The KEY OUT GPIO 1 is send to HIGH (5 volts)
; and LOW (0 V) with a delay of 250 msec. It will continue till the paddle is released.
; Otherwise KEY OUT will be in the LOW state(0 volts).
; To verify we connect an LED from pin no 6 with a resistor 2K7.
;..............................................
; Till now we have not used any RAM which is also called GENERAL PURPOSE REGISTER
; in microprocessor/microcontroller world
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
; 2MHz 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
BCF STATUS,RP0 ; Changing to bank 0
GOTO begin ; Goto begin
pause MOVLW 0XFF ; move "FF(HEX)" value into the W register
MOVWF COUNT1 ; presetting COUNT1 register with the value of W register
MOVLW 0X80 ; 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 IS ON)
CALL pause ; Call delay
BCF GPIO,1 ; Clearing the GP1 pin (0 V) (LED is OFF)
CALL pause ; Call delay
GOTO check ; goto run to check the condition and repeat the loop ; forever
ditOFF BCF GPIO,1 ; when the input is high(5 V) make the GPIO pin no 1 ; as LOW(LED iS OFF)
GOTO check ; goto run to check the condition and repeat the loop
begin NOP
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
GOTO ditOFF ; goto dash
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: one instruction cycle consists of 4 oscillations, to execute one instruction
; it wil take 2 usec since clock is 2MHz
; DECFSZ and GOTO instruction will take 2 instruction cycle each
; 255usec* 4 = 2 mses
; repeating the loop for 128 times => 256 msec of delay.
Here is the HEX code;
:020000040000FA
:100000000301B001B101000083160F168F120F1704
:10001000831285010730990083169F0138308500CF
:1000200083122228FF30B0008030B100B00B1628B8
:10003000B10B1628080085141220851012202328E1
:0C004000851023280000851E1B282028A6
:00000001FF
No comments:
Post a Comment