Wednesday, July 30, 2014
Thursday, July 24, 2014
LM35 THERMOMETER USING PIC16F88
Dear all,
A simple thermometer using PIC16F88 and LM35.
Here we are using TWO common anode 7 segment display for the OUTPUT indication.
The two 7 segment displays are multiplexed. Switching of the displays are happening with the help of two BC547 transistor.
Lm35 sensor is connected to the AN1(18 th pin of IC).
The connections of the seven segment display is shown in the below fig.
ASM code :
LIST P=16F88 #INCLUDE <P16F88.INC> CBLOCK 0X30 COUNT COUNT4 COUNT6 COUNT3 D1 RES1 RES2 RES3 RES4 A1 A2 B1 B2 NEG_FLAG SHIFTH SHIFTM SHIFTL BCOUNT NRATORH NRATORM NRATORL DENOMH DENOMM DENOML REMAINH REMAINM REMAINL LOWBYTE HIGHBYTE HUNS TENS ONES ENDC ORG 0X0000 NOP NOP NOP NOP CLRF PORTA CLRF PORTB BSF STATUS,RP0 ; SELECT BANK 1 BCF STATUS,RP1 BSF OSCCON,6 ; SETUP THE INTERNAL OSCILLATOR BSF OSCCON,5 ; TO USE 4MHZ MOVLW H'07' ; TURN OFF THE COMPARATORS MOVWF CMCON MOVLW B'00000011' MOVWF TRISA MOVLW B'00000000' MOVWF TRISB MOVLW B'00000011' MOVWF ANSEL BCF STATUS,RP0 ; SELECT BANK 0 BCF STATUS,RP1 GOTO START ADC_INITIALISE BCF STATUS,RP0 ; SELECT BANK 0 BCF STATUS,RP1 BCF ADCON0,GO BCF ADCON0,ADCS1 ; SELECTING THE FOSC FOR THE A/D BSF ADCON0,ADCS0 ; HERE WE HAVE SELECTED FOSC/16 BCF ADCON0,CHS2 BCF ADCON0,CHS1 BSF ADCON0,CHS0 BSF STATUS,RP0 ; SELECT BANK 1 BCF STATUS,RP1 BCF ADCON1,ADFM BSF ADCON1,ADCS2 BCF ADCON1,VCFG1 ; SELECT THE SOURCE OF THE VREF BCF ADCON1,VCFG0 BCF STATUS,RP0 ; SELECT BANK 0 BCF STATUS,RP1 BSF ADCON0,ADON ; TURN ON THE A/D MODULE ; CALL DELAY ; WAIT FOR THE AQUISTION TIME BSF ADCON0,GO ; CALL DELAY ; WAIT FOR SOME TIME HERE BTFSC ADCON0,GO GOTO HERE MOVF ADRESH,0 MOVWF LOWBYTE CLRF HIGHBYTE RETURN MULTIPLY: CLRF RES4 CLRF RES3 CLRF RES2 MOVLW 0X80 MOVWF RES1 CLRF NEG_FLAG BTFSS A2,7 GOTO A_POS COMF A2,F COMF A1,F INCF A1,F BTFSC STATUS, Z INCF A2,F INCF NEG_FLAG, F A_POS BTFSS B2,7 GOTO NEXTBIT COMF B2,F COMF B1,F INCF B1,F BTFSC STATUS, Z INCF B2,F INCF NEG_FLAG, F NEXTBIT RRF A2,F RRF A1,F BTFSS STATUS, C GOTO NOBIT_L MOVF B1,W ADDWF RES2,F MOVF B2, W BTFSC STATUS, C INCFSZ B2, W ADDWF RES3, F BTFSC STATUS, C INCF RES4, F BCF STATUS, C NOBIT_L BTFSS A1, 7 GOTO NOBIT_H MOVF B1,W ADDWF RES3,F BTFSC STATUS, C INCF RES4,F MOVF B2,W ADDWF RES4,F NOBIT_H RRF RES4,F RRF RES3,F RRF RES2,F RRF RES1,F BTFSS STATUS, C GOTO NEXTBIT BTFSS NEG_FLAG, 0 GOTO NO_INVERT COMF RES4,F COMF RES3,F COMF RES2,F COMF RES1,F INCF RES1,F BTFSC STATUS,Z INCF RES2,F BTFSC STATUS,Z INCF RES3,F BTFSC STATUS,Z INCF RES4,F NO_INVERT RETURN DIVIDE: MOVLW .24 MOVWF BCOUNT MOVF NRATORH,W MOVWF SHIFTH MOVF NRATORM,W MOVWF SHIFTM MOVF NRATORL,W MOVWF SHIFTL CLRF NRATORH CLRF NRATORM CLRF NRATORL CLRF REMAINH CLRF REMAINM CLRF REMAINL DLOOP BCF STATUS,C RLF SHIFTL,F RLF SHIFTM,F RLF SHIFTH,F RLF REMAINL,F RLF REMAINM,F RLF REMAINH,F MOVF DENOMH,W SUBWF REMAINH,W BTFSS STATUS,Z GOTO NOCHK MOVF DENOMM,W SUBWF REMAINM,W BTFSS STATUS,Z GOTO NOCHK MOVF DENOML,W SUBWF REMAINL,W NOCHK BTFSS STATUS,C GOTO NOGO MOVF DENOML,W SUBWF REMAINL,F BTFSS STATUS,C DECF REMAINM,F MOVF REMAINM,W XORLW 0XFF BTFSC STATUS,Z DECF REMAINH,F MOVF DENOMM,W SUBWF REMAINM,F BTFSS STATUS,C DECF REMAINH,F MOVF DENOMH,W SUBWF REMAINH,F BSF STATUS,C NOGO: RLF NRATORL,F RLF NRATORM,F RLF NRATORH,F DECFSZ BCOUNT,F GOTO DLOOP RETURN HEX2DEC INCF LOWBYTE ; PRE-LOAD TEMPHI + 1 CLRF HUNS ; HUNS = 0000 0000 MOVLW D'246' ; MOVE DECIMAL'246' TO W MOVWF TENS ; TENS GPR = 1111 0101 MOVWF ONES ; ONES GPR = 1111 0101 DECFSZ LOWBYTE, F ; DECREMENT TEMPHI REGISTER GOTO $+D'2' ; NOT 0, SKIP NEXT INSTRUCTION GOTO $+D'7' INCFSZ ONES, F GOTO $-D'4' INCFSZ TENS, F GOTO $-D'7' INCF HUNS, F GOTO $-D'10' SUBWF TENS, F SUBWF ONES, F RETURN DELAY MOVLW 0XFF MOVWF COUNT3 MOVLW 0X0A MOVWF COUNT4 WAIT DECFSZ COUNT3,F GOTO WAIT DECFSZ COUNT4,F GOTO WAIT RETURN DISPLAY MOVLW 0X30 MOVWF COUNT6 HERE1 BSF PORTA,3 BCF PORTA,2 MOVF TENS,0 CALL TABLE1 MOVWF PORTB CALL DELAY BCF PORTA,3 BSF PORTA,2 MOVF ONES,0 CALL TABLE1 MOVWF PORTB CALL DELAY DECFSZ COUNT6,F GOTO HERE1 RETURN TABLE1 ADDWF PCL,F RETLW B'00010001' ; 0 RETLW B'11010111' ; 1 RETLW B'00110010' ; 2 RETLW B'10010010' ; 3 RETLW B'11010100' ; 4 RETLW B'10011000' ; 5 RETLW B'00011000' ; 6 RETLW B'11010011' ; 7 RETLW B'00010000' ; 8 RETLW B'10010000' ; 9 START NOP CALL ADC_INITIALISE ; 2000 = H'7D0' CLRF A2 MOVLW 0X3C MOVWF A1 MOVF HIGHBYTE,W MOVWF B2 MOVF LOWBYTE,W MOVWF B1 CALL MULTIPLY ; 125*ANALOG READ MOVF RES3,W MOVWF NRATORH MOVF RES2,0 MOVWF NRATORM MOVF RES1,0 MOVWF NRATORL CLRF DENOMH MOVLW H'00' ; 256 = H'FF' MOVWF DENOMM CLRF DENOML MOVLW 0XFF MOVWF DENOML CALL DIVIDE MOVF NRATORM,0 MOVWF HIGHBYTE ; TENTHS DEGREES MOVF NRATORL,0 MOVWF LOWBYTE ; TENTHS CALL HEX2DEC CALL DISPLAY GOTO START END
HEX file:
:020000040000FA :100000000000000000000000850186018316031334 :100010000F178F1607309C000330850000308600D4 :1000200003309B0083120313D828831203131F117C :100030009F131F179F121F129F15831603139F13E1 :100040001F179F121F12831203131F141F151F194E :1000500027281E08CB00CC010800B801B701B60163 :100060008030B500BD01BA1F3B28BA09B909B90AE9 :100070000319BA0ABD0ABC1F4328BC09BB09BB0A45 :100080000319BC0ABD0ABA0CB90C031C50283B0862 :10009000B6073C0803183C0FB7070318B80A03104B :1000A000B91F58283B08B7070318B80A3C08B80717 :1000B000B80CB70CB60CB50C031C43283D1C6B28C0 :1000C000B809B709B609B509B50A0319B60A03197B :1000D000B70A0319B80A08001830C1004208BE0068 :1000E0004308BF004408C000C201C301C401C801E5 :1000F000C901CA010310C00DBF0DBE0DCA0DC90D47 :10010000C80D45084802031D8B2846084902031DF7 :100110008B2847084A02031C9C284708CA02031C74 :10012000C9034908FF3A0319C8034608C902031C5A :10013000C8034508C8020314C40DC30DC20DC10B8A :100140007A280800CB0ACD01F630CE00CF00CB0BC9 :10015000AA28B028CF0FA728CE0FA628CD0AA528F9 :10016000CE02CF020800FF30B3000A30B100B30B5B :10017000B728B10BB72808003030B200851505113B :100180004E08CD208600B320851105154F08CD20DF :100190008600B320B20BBE28080082071134D73482 :1001A00032349234D43498341834D33410349034F4 :1001B00000001520BA013C30B9004C08BC004B08C7 :1001C000BB002D203708C2003608C3003508C40024 :1001D000C5010030C600C701FF30C7006C204308CE :0C01E000CC004408CB00A220BC20D82892 :00000001FF
Saturday, July 19, 2014
SOME THOUGHTS ON PYTHON (high level language)
Nowadays we can see PYTHON as one of the emerging language in the industry because of ease of use. Python is a high level language and any one can understand very easily.
PYTHON IS AN "OPEN SOURCE" and can "FREELY DOWNLOAD" from the website.
We can start our programming in less than 2 Hrs of time. because it very easy to learn and practice.
It does not require a compiler whereas it needs an interpreter.
Many tutorials are available in the web, we have given below the way we are learning PYTHON step by step.
For more info on PYTHON please visit www.python.org
Installation of Python:
Download the latest version of PYTHON file from the website.
Click here for the direct download .
Double click on the .msi file for installation with default settings
C: / PythonXYZ
where XYZ is version
while installing check this step for enabling the path
Check on Finish button to complete the installation of PYTHON.
Click on the python shell/GUI icon created on the desktop
Now we can write and check the program in the python shell.
print the hello world program
Write the code as follows
print ' hello world'
and press the enter button
We can you single quote, double quote also to print the string.
Till now we have seen output when we press the OUTPUT button .
If can change the procedure to check the output as follows
à Go
to file and open a new file.
à Save the file with an extension of .py/.pyw
à Now write basic HELLO WORLD program and check the OUTPUT by compiling or by
pressing the F5 button.
à We can see output in the GUI/SHELL window.
Wednesday, July 16, 2014
Monday, July 14, 2014
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 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
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
Monday, July 7, 2014
Saturday, July 5, 2014
BUJJI BUG PART 5
Everyone would like to operate the BUJJI BUG at their individual speed. To INCREASE/DECREASE speed of the KEY we are using EEPROM.
For this we need to WRITE and READ the value from EEPROM. Hence we are giving a small tutorial on how to do.
This can be used in other programs also to store the value after the POWER CUT .
; BUJJI BUG
; Code to WRITE and READ from the EEPROM
processor 16F628A ; Selected 16F628A
#include <P16F628A.INC> ; Including the headerfile
; In this program we writing into EEPROM and reading the value back to PORTB
; We are suppose to use EEPROM for INCREMENT/DECREMENT the KEY speed.
; For checking the working of EEPROM. we are giving a small example program.
; To varify we connected an LED's from PORTB through the resistor.
ORG 0X00 ; Starting address for microcontroller program
NOP ; NO operation
NOP ; NO operation
NOP ; NO operation
NOP ; This location is reserved for INTERRUPT and
;Initialising the INPUT and OUTPUT ports
CLRF PORTB ; Clearing the PORTB registers
MOVLW 0X07 ; Moving the "7(HEX)" into the W register
MOVWF CMCON ; Comparators are disabled
BSF STATUS,RP0 ; Selecting BANK 1
BCF STATUS,RP1 ; Selecting BANK 1
CLRF TRISB ; Making PORTB as OUTPUT
; Writing into EEPROM
MOVLW 0X00 ; Writing value 0 into W register
MOVWF EEADR ; Selecting the Address 0 in EEPROM to write
MOVLW 0X10 ; Moving value 10 (HEX) in W register
MOVWF EEDATA ; Selecting the value 10 (HEX) to write into EEPROM
BSF EECON1,WREN ; Enabling the WRITE cycle
;......................................................................................................
MOVLW 0X55 ; Writing value 55 (HEX) into W register
MOVWF EECON2 ; Passing the value into the EECON2 REGISTER
MOVLW 0XAA ; Writing value AA (HEX) into W register
MOVWF EECON2 ; Passing the value into the EECON2 REGISTER
;......................................................................................................
;Without the above four step the data cannot read into the EEPROM
BSF EECON1,WR ; Enabling WR bit of EECON1 to write into the EEPROM
wait BTFSC EECON1,WR ; Varifying whether the data is written into EEPROM or not
GOTO wait ; If yes skip this line otherwise goto wait
; Reading from EEPROM
MOVLW 0X00 ; Writing value 55 (HEX) into W register
MOVWF EEADR ; Selecting the address 0 in EEPROM to read
BSF EECON1,RD ; Enabling the RD bit to Read the data from EEPROM
MOVF EEDATA,W ; Moving the data into the W register
wait1 BTFSC EECON1,RD ; Varifying whether the data is written into EEPROM or not
GOTO wait1 ; If yes skip this line otherwise goto wait1
BCF STATUS,RP0 ; Coming back to BANK 0
BCF STATUS,RP1 ; Coming back to BANK 0
MOVWF PORTB ; Writing the EEPROM DATA into PORTB
END ; END of the program
; NOTE 1: 11 instruction are used out of 35
; NOTE 2: 9 SPECIAL FUNCTION REGISTER used 38
; NOTE 3: 31 Bytes of memory is used
; NOTE 4: The program is running with internal oscillator at default 4MHz clock speed.
HEX Code:
:020000040000FA
:100000000000000000000000860107309F008316FA
:100010000313860100309B0010309A001C155530E8
:100020009D00AA309D009C149C18142800309B0051
:0E0030001C141A081C181A28831203138600C9
:00000001FF
For this we need to WRITE and READ the value from EEPROM. Hence we are giving a small tutorial on how to do.
This can be used in other programs also to store the value after the POWER CUT .
; BUJJI BUG
; Code to WRITE and READ from the EEPROM
processor 16F628A ; Selected 16F628A
#include <P16F628A.INC> ; Including the headerfile
; In this program we writing into EEPROM and reading the value back to PORTB
; We are suppose to use EEPROM for INCREMENT/DECREMENT the KEY speed.
; For checking the working of EEPROM. we are giving a small example program.
; To varify we connected an LED's from PORTB through the resistor.
ORG 0X00 ; Starting address for microcontroller program
NOP ; NO operation
NOP ; NO operation
NOP ; NO operation
NOP ; This location is reserved for INTERRUPT and
;Initialising the INPUT and OUTPUT ports
CLRF PORTB ; Clearing the PORTB registers
MOVLW 0X07 ; Moving the "7(HEX)" into the W register
MOVWF CMCON ; Comparators are disabled
BSF STATUS,RP0 ; Selecting BANK 1
BCF STATUS,RP1 ; Selecting BANK 1
CLRF TRISB ; Making PORTB as OUTPUT
; Writing into EEPROM
MOVLW 0X00 ; Writing value 0 into W register
MOVWF EEADR ; Selecting the Address 0 in EEPROM to write
MOVLW 0X10 ; Moving value 10 (HEX) in W register
MOVWF EEDATA ; Selecting the value 10 (HEX) to write into EEPROM
BSF EECON1,WREN ; Enabling the WRITE cycle
;......................................................................................................
MOVLW 0X55 ; Writing value 55 (HEX) into W register
MOVWF EECON2 ; Passing the value into the EECON2 REGISTER
MOVLW 0XAA ; Writing value AA (HEX) into W register
MOVWF EECON2 ; Passing the value into the EECON2 REGISTER
;......................................................................................................
;Without the above four step the data cannot read into the EEPROM
BSF EECON1,WR ; Enabling WR bit of EECON1 to write into the EEPROM
wait BTFSC EECON1,WR ; Varifying whether the data is written into EEPROM or not
GOTO wait ; If yes skip this line otherwise goto wait
; Reading from EEPROM
MOVLW 0X00 ; Writing value 55 (HEX) into W register
MOVWF EEADR ; Selecting the address 0 in EEPROM to read
BSF EECON1,RD ; Enabling the RD bit to Read the data from EEPROM
MOVF EEDATA,W ; Moving the data into the W register
wait1 BTFSC EECON1,RD ; Varifying whether the data is written into EEPROM or not
GOTO wait1 ; If yes skip this line otherwise goto wait1
BCF STATUS,RP0 ; Coming back to BANK 0
BCF STATUS,RP1 ; Coming back to BANK 0
MOVWF PORTB ; Writing the EEPROM DATA into PORTB
END ; END of the program
; NOTE 1: 11 instruction are used out of 35
; NOTE 2: 9 SPECIAL FUNCTION REGISTER used 38
; NOTE 3: 31 Bytes of memory is used
; NOTE 4: The program is running with internal oscillator at default 4MHz clock speed.
HEX Code:
:020000040000FA
:100000000000000000000000860107309F008316FA
:100010000313860100309B0010309A001C155530E8
:100020009D00AA309D009C149C18142800309B0051
:0E0030001C141A081C181A28831203138600C9
:00000001FF
Friday, July 4, 2014
BUJJI BUG PART 4
This is BUJJI BUG part 4 for semi electronic generating Dit and dash.
; BUJJI BUG
; CODE FOR DIT and DASH generation.
list p = 12F683 ; Selected 12F683
#include<p12F683.inc> ; Includeing 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 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
BCF 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 ; 1MHz 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
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 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 ; 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 check to CHECK the condition and repeat the loop
dashON BSF GPIO,1 ; make the GPIO 1 (pin no 6 of IC) to HIGH
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(LED iS OFF)
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 1MHZ 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 4 usec since clock is 1MHz
; DECFSZ and GOTO instruction will take 2 instruction cycle each
; 255usec* 16 = 4 mses
; repeating the loop for 20 times => 80 msec of delay.
; NOTE 7: 12 INSTRUCTIONS USED out of 35 INSTRUCTIONS
; 2 GENERAL PURPOSE REGISTER
; 6 SPECIAL FUNCTION REGISTER
; 20 bytes of data memory used out of 256 bytes.
Here is the HEX code for BUJJI BUG part 4
:020000040000FA
:100000000301B001B101000083160F168F120F1704
:10001000831285010730990083169F0138308500CF
:1000200083122228FF30B0008030B100B00B1628B8
:10003000B10B1628080085141220851012202328E1
:0C004000851023280000851E1B282028A6
:00000001FF
; BUJJI BUG
; CODE FOR DIT and DASH generation.
list p = 12F683 ; Selected 12F683
#include<p12F683.inc> ; Includeing 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 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
BCF 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 ; 1MHz 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
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 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 ; 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 check to CHECK the condition and repeat the loop
dashON BSF GPIO,1 ; make the GPIO 1 (pin no 6 of IC) to HIGH
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(LED iS OFF)
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 1MHZ 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 4 usec since clock is 1MHz
; DECFSZ and GOTO instruction will take 2 instruction cycle each
; 255usec* 16 = 4 mses
; repeating the loop for 20 times => 80 msec of delay.
; NOTE 7: 12 INSTRUCTIONS USED out of 35 INSTRUCTIONS
; 2 GENERAL PURPOSE REGISTER
; 6 SPECIAL FUNCTION REGISTER
; 20 bytes of data memory used out of 256 bytes.
Here is the HEX code for BUJJI BUG part 4
:020000040000FA
:100000000301B001B101000083160F168F120F1704
:10001000831285010730990083169F0138308500CF
:1000200083122228FF30B0008030B100B00B1628B8
:10003000B10B1628080085141220851012202328E1
:0C004000851023280000851E1B282028A6
:00000001FF
Subscribe to:
Posts (Atom)