P. 1
Expt 1

Expt 1

|Views: 47|Likes:
Published by Pic Micro

More info:

Published by: Pic Micro on Jul 17, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less

07/17/2011

pdf

text

original

Experiment 1.

Test Port A Bit 0 ON LED First Experiment we will test Port RA by on RA0 that connect to LED the schematic for Experiment 1is shown below in Figure 1

Figure 1.1 schematic for Experiment 1Test ON LED ON Port A Bit 0 Assemble circuit as figure 1.1 and load Programming to PIC16F628 after that on power supply you will see result it Source Code For Experiment 1 list p=16f628 ; list directive to define processor #include <p16f628.inc> ; processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF org clrf movlw movwf bsf movlw movwf bcf bcf goto END 0x000 PORTA 0x07 CMCON STATUS,RP0 b'11111110' PORTA STATUS,RP0 PORTA,0 $

; Initial PORT A ; output data latches ; Turn Comparator off and ; Enable pins for I/O ; Select Bank 1 ; All PORTA = Input ; RA0 = Output ; Return to Bank 0 ; RA0 = 0 LED "ON" ; end of program'
1

Tools & Components Name List MPLAB PIC16F628 4 MHz Crystal LED 33 pF Capacitors 1K Resistors 4.7K Resistors Push Button Switch Quantity 1 1 1 2 1 1 1

;********************************************************************** ; ; Filename: Experiment 1. Test Port A Bit 0 ON LED ; ; www.electronics-microcontroller.com ; ;********************************************************************** list p=16f628 #include <p16f628.inc> ; list directive to define processor ; processor specific variable definitions

__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF org clrf movlw movwf bsf movlw movwf bcf bcf goto END 0x000 PORTA 0x07 CMCON STATUS,RP0 b'11111110' PORTA STATUS,RP0 PORTA,0 $ ; ; ; ; ; ; ; ; Initial PORTA Turn Comparator off and Enable pins for I/O Select Bank 1 All PORTA = Input RA0 = Output Return to Bank 0 RA0 = 0 LED "ON"

; end of program

2

bcf STATUS. Assemble circuit as figure 2. RA0 = 0 LED "ON" goto $ END . Select Bank 1 movlw b'11111111' . output data latches movlw 0x07 .0 . If Press Set RA0 = Output bcf PORTA. Test Switch Press ? goto $-1 .RP0 .0 . All PORTA = Input movwf PORTA .inc> . processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF org 0x000 clrf PORTA . If Not Press Loop bsf STATUS.0 .RP0 . Input & Output on Port A The Experiment 2 we will test Port A is both Input and Output . end of program' 3 .Experiment 2.RP0 . Return To Bank 0 bcf PORTA. TRISA bcf STATUS. Initial POR TA .RP0 .1 schematic for Experiment 2 Input & Output on Port A Assemble circuit as figure 2. Turn Comparator off and movwf CMCON . Enable pins for I/O bsf STATUS. Return to Bank 0 btfsc PORTA. list directive to define processor #include <p16f628.1 and Down load Programming to PIC16F628 list p=16f628 .1 and Download Program to PIC16F628 Figure 2.

end of program 4 . Filename: Experiment 2. Input & Output on Port A . . . . .7K Resistors 1K Resistors 2 2 1 1 Resources . .********************************************************************** .0 STATUS.RP0 PORTA.0 $ END . .2 Flowchart of Experiment 2 Tools & Components Name List MPLAB PIC16F628 4 MHz Crystal LED Quantity 1 1 1 Push Button Switch 1 PC 33 pF Capacitors 4. .electronics-microcontroller. .RP0 PORTA. processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF org clrf movlw movwf bsf movlw movwf bcf btfsc goto bsf bcf bcf bcf goto 0x000 PORTA 0x07 CMCON STATUS.com .RP0 b'11111111' PORTA STATUS.RP0 PORTA.From The Source Code we can be explain by flowchart as figure 2.inc> . www. list directive to define processor #include <p16f628. Initial PORTA Turn Comparator off and Enable pins for I/O Select Bank 1 All PORTA = Input Return to Bank 0 Test Switch Press ? If Not Press Loop If Press Set RA0 = Output TRISA Return To Bank 0 RA0 = 0 LED "ON" . .0 $-1 STATUS. . .********************************************************************** list p=16f628 .2 Figure 2. .Tools & Related .

1 for to understand Figure 3. Sound Generated The Experiment 3 we will Generated sound (one frequency) by use PIC16F628 .2 and load Programming to PIC16F628 Figure 3. The Frequency can be calculate by formula as below f = 1/ T 1/(768 uSec + 768 uSec) = 651 Hz Source Code For Experiment 3 5 .Experiment 3.1 Timing Diagram for Sound Generated Assemble circuit as figure 3. first of all see Timing Diagram as figure 3.2 and load Program to PIC16F628 . RA4 Connect with PIEZO .2 schematic for Experiment 3 Sound Generated Assemble circuit as figure 3.

processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF org 0 x 000 clrf PORTA . Other = Input bcf STATUS.RP 0 .3 Figure 3. = 651 Hz Delay clrf 0 x 20 . Initial PORTA . output data latches movlw 0 x 07 .RP 0 . Low RA 4 768 usec call Delay goto Loop1 .f goto $-1 return END From The Source Code we can be explain by flowchart as figure 3. Delay 768 usec decfsz 0 x 20 .list p= 16 f 628 . Return to Bank 0 Loop1 bsf PORTA. list directive to define processor #include <p 16 f 628.3 Flowchart of Experiment 3 Tools & Components 6 . 4 . High RA 4 768 usec call Delay bcf PORTA. RA 4 = Output movwf PORTA . Enable pins for I/O bsf STATUS. Turn Comparator off and movwf CMCON . 4 . Frequency = 1/(768 usec + 768 usec) . inc> . Select Bank 1 movlw b' 11101111 ' .

Delay 768 usec 651 Hz Delay clrf 0x20 decfsz goto $-1 return END 7 . Sound Generated . Return to Bank 0 . Input & Output on Port A .Name List MPLAB PIC16F628 4 MHz Crystal Push Button Switch 1 PC 33 pF Capacitors 4.Tools & Related Quantity 1 1 1 2 1 1 1 Download Source Code of Experiment 2. list directive to define processor . Frequency = 1/(768 usec + 768 usec) = .inc> definitions . Enable pins for I/O . . RA4 = Output .********************************************************************** . .RP0 b'11101111' PORTA STATUS.com .electronics-microcontroller. Initial PORTA .7K Resistors 1K Resistors PIEZO Resources .RP0 PORTA. .f . Select Bank 1 .********************************************************************** list p=16f628 #include <p16f628. Filename: Experiment 3.4 Delay PORTA. www. High RA4 768 usec . processor specific variable __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF org clrf movlw movwf bsf movlw movwf bcf Loop1 bsf call bcf call goto 0x000 PORTA 0x07 CMCON STATUS. Turn Comparator off and . Other = Input . Low RA4 768 usec . output data latches .4 Delay Loop1 0x20.

If No Continue Check movlw 0 x 20 . Enable pins for I/O bsf STATUS. Select Bank 1 movlw 0x0F . If RA 0 Press movwf TIME . Start Rising Pulse call Delay . Test RA 0 Press goto Loop1 .w . If RA 1 Press movwf TIME .1 and Download Program to PIC16F628 Figure 4. bcf STATUS. Turn Comparator off and movwf CMCON . RA 0. If No Continue Check movlw 0 x 55 .1 schematic for Experiment 4 Sound Melody list p= 16 f 628 . for this experiment we will apply Exp 3 to Generated Sound more one frequency like melody Assemble circuit as figure 4. Test RA 1 Press goto Check 1 . output data latches movlw 0 x 07 . Test RA 3 Press goto Check 2 . 3 .Experiment 4. If No Begin Pulse Again movlw 0 x 60 . inc> . Set Time = 55 H goto Loop1 . Return to Bank 0 Loop1 bsf PORTA. 4 . Continue Check 1 btfsc PORTA. Begin Pulse Again Delay movf TIME.RP 0 . 1 . If RA 3 Press Set Time = 20 H movwf SETTIME goto Loop1 .RA 3 = Input RA 4 = Output movwf PORTA .f goto $-1 return END . Sound Generated The previously experiment (Exp 3) we can Generated Sound at one frequency. processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF COUNT equ 0 x 20 SETTIME equ 0 x 21 org 0 x 000 clrf PORTA . Falling Pulse call Delay btfsc PORTA. Delay Use Change Delay Time movwf COUNT . Continue Check 2 btfsc PORTA. 0 . Initial PORTA . of program 8 . list directive to define processor #include <p 16 f 628.RP 0 . Delay bcf PORTA. With TIME Register decfsz COUNT. 4 . Set Time = 60 H goto Loop1 .

If RA3 Press Set Time = 20H . Enable pins for I/O .4 Delay PORTA. processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF COUNT SETTIME org clrf movlw movwf bsf movlw movwf bcf LOOP1 bsf call bcf call btfsc goto movlw movwf goto Check2 goto movlw movwf goto Check1 goto movlw movwf goto equ equ 0x000 PORTA 0x07 0x20 0x21 . Return to Bank 0 . Test RA3 Press . If No Continue Check . output data latches .7K Resistors Quantity 1 1 4 2 1 1K Resistors 220 Resistors PIEZO LED 1K Resistors 220 Resistors PIEZO 3 3 1 3 3 3 1 . Set Time = 60H .Tools & Components Name List MPLAB PIC16F628 4 MHz Crystal Push Button Switch 1 PC 33 pF Capacitors 4. If RA0 Press .RP0 PORTA. Delay Use Change Delay Time . Filename: Experiment 4. If RA1 Press . . Test RA0 Press . Continue . Sound Generated list p=16f628 . Start Rising Pulse .inc> .f goto $-1 return END . Select Bank 1 . list directive to define processor #include <p16f628.0 LOOP1 0x60 TIME LOOP1 Delay movf TIME. Falling Pulse . Turn Comparator off and . Test RA1 Press . Begin Pulse Again .RP0 0x0F PORTA STATUS. Set Time = 55H . Delay .3 Check2 0x20 SETTIME LOOP1 btfsc PORTA.w movwf COUNT decfsz COUNT. If No Begin Pulse Again . If No Continue Check . With TIME Register CMCON STATUS.1 Check1 0x55 TIME LOOP1 btfsc PORTA. Initial PORTA . of program 9 . Continue . RA0-RA3 =Input RA4 = Output .4 Delay PORTA.

5 Degree/Step .Experiment 5.1 VR 100k use for adjust frequency clock of PIC16F628 when run in mode ER 10 . and use IC ULN2003 for Drive Unipolar Motors IC ULN2003 Figure 5. Stepper Motor Drive The Experiment 5 we will test Use PIC16F628 to Drive Stepper Motor.Tools & Related Menu below This Experiment use Unipolar Motors 9-24 V 7.1 and Download Program to PIC16F628 from Figure 5.1 schematic for Experiment 5 Stepper Motor Drive Assemble circuit as figure 5. for Article & Types of Stepping Motors you and see links as Resources .

list p= 16 f 628 . Delay Between Step movwf DUMMY 1 Delay 1 clrf DUMMY 2 decfsz DUMMY 2 . Check Loop = 12 Time ? goto Loop . If Yes Start Again Delay movlw 0 x 20 .f .12 .f .5 Degree/Step . list directive to define processor #include <p 16 f 628. end of program 11 .5 = 360 movwf COUNT Loop movlw b' 00010000 ' .f goto Delay 1 return END . Change Delay For Change Speed movlw b' 00100000 ' movwf PORTB call Delay movlw b' 01000000 ' movwf PORTB call Delay movlw b' 10000000 ' movwf PORTB call Delay decfsz COUNT. 4x12x7. inc> . processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _ER_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF COUNT equ 0 x 20 DUMMY 1 equ 0 x 21 DUMMY 2 equ 0 x 22 org 0 x 000 . Reset Vetor Address bsf STATUS.12 . 1 Phase Full Step movwf PORTB call Delay . Set RB 4.f goto $-1 decfsz DUMMY 1 . Check Loop = Time ? goto Loop 2 goto Begin . If Not Loop Again movlw .RP 0 Begin movlw .RB 7 For Drive Stepper Motor movlw b' 00001111 ' movwf PORTB bcf STATUS.RP 0 . Loop 12 Time For 7. Reverse Move 12 Time movwf COUNT Loop 2 movlw b' 01000000 ' movwf PORTB call Delay movlw b' 00100000 ' movwf PORTB call Delay movlw b' 00010000 ' movwf PORTB call Delay movlw b' 10000000 ' movwf PORTB call Delay decfsz COUNT.

Reverse Move 12 Time . Change Delay For Change Speed . Set RB4-RB7 For Drive Stepper Motor 0x000 STATUS. Loop 12 Time For 7.f goto Loop2 goto Begin Delay movlw 0x20 movwf DUMMY1 Delay1 clrf DUMMY2 decfsz DUMMY2..RP0 Begin movlw . 1 Phase Full Step .f goto $-1 decfsz DUMMY1. If Not Loop Again . Check Loop = 12 Time ? .Filename: Experiment 5.f goto Loop movlw . Stepper Motor Drive list p=16f628 . If Yes Start Again . of program 12 . Check Loop = Time ? . Delay Between Step .RP0 b'00001111' PORTB STATUS.f goto Delay1 return END .5 Degree/Step 4x12x7. Reset Vetor Address .5 = 360 . list directive to define processor #include <p16f628. processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _ER_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF COUNT DUMMY1 DUMMY2 org bsf movlw movwf bcf equ equ equ 0x20 0x21 0x22 .12 movwf COUNT Loop movlw b'00010000' movwf PORTB call Delay movlw b'00100000' movwf PORTB call Delay movlw b'01000000' movwf PORTB call Delay movlw b'10000000' movwf PORTB call Delay decfsz COUNT.inc> .12 movwf COUNT Loop2 movlw b'01000000' movwf PORTB call Delay movlw b'00100000' movwf PORTB call Delay movlw b'00010000' movwf PORTB call Delay movlw b'10000000' movwf PORTB call Delay decfsz COUNT.

This circuit can control a outside system by driving a relay.com * . For thermometer use DS1820 which is 1±Wire Digital Thermometer Feature LCD Temperature Display Can control a outside system by driving a relay Can Adjust temperature Hardware Completed circuit of Digital Thermostat show in figure 1 .Guidecircuit.************************************************************************ . Output can control outside by relay Figure 1. For temperature display use LCD Module 16X2 for display. Schematics of Digital thermostat . Digital Thermostst * . From figure 1 PIC16F628 is main device of circuit which keep source for control. WWW. DS1820 is thermometer which DS1820 is 1-wire thermometer.************************************************************************ 13 .Digital thermostat using PIC16F628 Digital thermostat in this project design from microcontroller PIC16F628 .

0 PORTB. dt "Room Temp " Set_ addwf PCL. Initial LCD movlw 0x20 .********************************************************************** . End of definition PORTA.********************************************************************** . Set -up port call Init_LCD . Main Program * . Set temperature data = 00100000b = 16.3 0x000 Start .********************************************************************** Room_ addwf PCL.-302 CBLOCK DS_DAT DS_SIGN SEND COUNT NUM1 NUM2 NUM3 DATA1 HALF DUMMY0 DUMMY1 DUMMY2 DUMMY5 DUMMY6 BITS COMPARE SET_TEMP ADDR endc #defineDQ #defineE #defineRS org goto 0x20 .list p=16f628 #include <p16f628. Define text substitution .0 PORTB.f .f dt "Set Temp " First_ addwf PCL.0C movwf SET_TEMP 14 .inc> errorlevel 0. LCD Display .********************************************************************** Start call Init_Port .f dt "<Set Temp First> " .

Delay for switch debouncing . Send data to LCD incf COUNT.C rrf SET_TEMP. If < 16.3 Again . Save half degree bcf STATUS. Check temperature increment switch . Send command for clearing display . Select the center of LCD's second line clrf HALF . first . Rotate bit data rlf HALF.w .9 subwf COUNT. try again 15 . still send data Again movlw 0xC5 movwf ADDR call Set_Addr .Z goto Send_Lp3 . Test counter < 8 ? btfss STATUS.1 Check_Run Delay200 SET_TEMP. Income data position COUNT call Send . Off relay. Get the next data if counter < 16 movlw . Send temperature value to LCD btfsc goto call incf Check_Run btfsc goto PORTA.f . Begin with counter = 0 call First_ . If not pressed. Nescessary delay clrf COUNT . If < 8. Get message from table Send_Lp2 movf COUNT.w . Select LCD's first line address clrf COUNT . Test counter < 16 ? btfss STATUS. Check running switch . movwf DATA1 .w .f PORTA. Get message from table Send_Lp3 movf COUNT. loop again movlw 0x01 movwf ADDR call Set_Addr call Delay5 .w .Z goto Send_Lp2 . Begin with counter = 0 call Set_ .w . Income data position COUNT call Send .f .16 subwf COUNT. Still send next data if counter < 8 movlw . Send data to LCD incf COUNT.bsf PORTA.f . .4 movlw 0x80 movwf ADDR call Set_Addr . Save for conversion call Convert call Send_Temp .

If not. Check room temp > setting temp ? SET_TEMP. Loop again .f .C ON_ .5) or (. try again OFF_ bsf PORTA.4 movlw 0xC9 movwf ADDR call Set_Addr call call call movf clrf bcf Send_Temp Delay200 RD_Temp DS_DAT. Begin with counter = 0 call Room_ .f movwf DATA1 call Convert movf subwf btfss goto . Send temperature value to LCD . Load data . Load data . Off relay .w rlf HALF. If more than. Select LCD's second line address movlw 0xC0 movwf ADDR call Set_Addr clrf COUNT .w .C rrf DS_DAT. Send data to LCD incf COUNT. Show room's temp bcf PORTA.call Send_Temp .4 call RD_Temp movf DS_DAT.0) . If < 8. Clear register for storing a half temp value .9 subwf COUNT. Data for conversion to decimal .w STATUS. show room's temp on LCD movlw 0xC9 movwf ADDR call Set_Addr call call goto ON_ Send_Temp Delay200 OFF_ . On relay . Test counter < 8 ? btfss STATUS. Read temperature value again .Z goto Send_Lp4 . Convert data to decimal DS_DAT. Use 7-bit upper . Clear register for storing a half temp 16 .w . Get message from Table Send_Lp4 movf COUNT. Still send next Data if counter < 8 movlw .w . Set address for LCD .w clrf HALF bcf STATUS. goto on relay .C . Income data position COUNT call Send . Store a half degree (.w HALF STATUS.

Reset chip first btfss STATUS. Set PORTA to digital I/O movwf CMCON bsf STATUS.1] ? SET_TEMP. loop again . Zero flag set = OK goto Error_ . Check temperature again 0x01 . Clear PORTA before initial movlw 0x07 . Send command 17 . SetPort I/O of PIC16F628 * . Sign (FF=-VE.********************************************************************** Init_Port clrf PORTA .w rlf HALF. Store a half degree (. RA4 as output movwf PORTA movlw b'00000110' . Read 8-bit data movwf DS_DAT .********************************************************************** RD_Temp call DS_Rx . Start convert command call DS_Tx . Send command movlw 0xbe . off relay OFF_ . Restart movlw 0xcc . Send command call DS_Rx . Zero flag set = ready return .C . W register is not zero = not ready Get_Temp call DS_Reset . If not response.RP0 return . If yes. If no. Temperarure is lower than [setting Temperature . Read Data From DS1820 * . 0= ready btfss STATUS. Use PORTB for LCD movwf PORTB bcf STATUS.Z . Check DS1820 status addlw 0x01 . Save 9th bit to register call DS_Reset . Skip ROM command call DS_Tx . RA1 and RA3 as input.0) .********************************************************************** .w . Data for decimal conversion DS_DAT. exit movlw 0xcc . Read scratch pad command call DS_Tx . 255=ready.RP0 movlw b'11101111' . Use 7-bit upper . ON_ . Save data to register call DS_Rx .f movwf DATA1 call Convert movf addlw subwf btfsc goto goto . Send command movlw 0x44 .w STATUS. 00=+VE) movwf DS_SIGN .rrf DS_DAT.********************************************************************** . Skip ROM command call DS_Tx .5) or (.Z . Set RA0.

Reset DS1820 * .Z Error_ 0x00 0x01 . Check dign = 00 ? . If Yes.********************************************************************** DelayAL nop . Set DQ to output bcf STATUS. DQ bit ready bsf STATUS. Wait 67 microsecond for response bit nop nop movf PORTA.w 18 . Generate delay time . (Temp as negstive then return .********************************************************************** DS_Reset DQLOW PAUSE 0x77 .RP0 endm DQHIZ bsf bsf bcf endm macro STATUS.RP0 bcf DQ .w STATUS. 600 microsecond delay DQHIZ PAUSE 0x0c . end with error . If yes.********************************************************************** DQLOW macro bcf DQ .movf btfsc goto addlw btfss goto Pass retlw Error_ retlw DS_SIGN.RP0 PAUSE macro DELAY movlw DELAY movwf DUMMY0 call DelayAL endm . MACRO For DS1820 * . Check dign .********************************************************************** .RP0 DQ .********************************************************************** .********************************************************************** . Temp as positive then return . If not. Check sign = FF ? . . Set DQ to input STATUS. Use for pausing macro nop decfsz DUMMY0.Z Pass 0x01 STATUS. DS1820 SubRoutine * .f goto DelayAL return .

Get data bit 0 only addlw 0xff . Macro of DQ pin to low. Move data bit 0 to DUMMY bit 7 PAUSE 0x0b .f . Save data to W register return .********************************************************************** DS_Rx movlw 0x08 .********************************************************************** . Prepare 8-bit counter for sending data movwf DUMMY1 .f .********************************************************************** .********************************************************************** DS_Tx movwf DUMMY2 . Recieve 8-bit data movwf DUMMY1 Rx_Loop DQLOW . Test Carry flag bsf DQ .********************************************************************** Send_Temp movf NUM3. No. 60 microsecond delay decfsz DUMMY1. this is start bit PAUSE 0x01 . 8 times ? goto Tx_Loop . This is start bit PAUSE 0x01 . 300 microsecond delay movf DUMMY1.w . Rotate data to Carry flag btfsc STATUS.f . send again return .w . Define loop counter Tx_Loop DQLOW . Back to high for receiving nop nop movf PORTA. Loop 8 times goto Rx_Loop .C . 10 microsecond delay DQHIZ . Transmission data movlw 0x08 . Read data andlw 0x01 . If Carry flag = "1" . Read data from DS1820 btfsc STATUS.f . Fisrt data = 0 ? movlw 0xe0 . Subroutine For Send Data To LCD * . 10 microsecond delay rrf DUMMY2.w . Recieve Data From DS1820 (8 Bit) * .Z . Use RA0 only movwf DUMMY1 PAUSE 0x3b . Move data bit 0 to Carry flag with addition method rrf DUMMY2. set DQ to high PAUSE 0x0d . Macro of DQ pin to low. Response in W register return . Read again movf DUMMY2.********************************************************************** . convert to blank 0xE0+0x30 =0x20 (" ") 19 . If yes.w .andlw 0x01 . Send Data To DS1820 (8 Bit) * . 70 microsecond delay DQHIZ nop decfsz DUMMY1.

. Fisrt.w Send RS Delay125 .w addlw 0x30 call Send movf NUM1. Convert number to ASCII . Send 4-bit mode command in MSB only . cursor off.' call Send movlw '0' btfsc HALF.0 movlw '5' call Send movlw 'C' call Send return Set_Addr bcf bcf call movf call bsf call return E RS Delay125 ADDR. . cursor not blink 20 . Select address for sending data to LCD reset_LCD macro movlw 0x38 movwf BITS call Flip call Pulse call Delay125 endm Init_LCD bcf E bcf RS call Delay125 reset_LCD reset_LCD reset_LCD reset_LCD movlw 0x28 movwf BITS call Flip call Pulse call Delay125 movlw 0x28 call Send movlw 0x0c .addlw 0x30 call Send movf NUM2. 2 line display. Test half degree = [0] or [5] . Fix position on LCD . Send data to LCD . send 8-bit mode command . Read second digit . Send command . Set command mode . Set LCD mode to 4 bit mode. Set LCD on. 5x7 dot . Convert to ASCII .w addlw 0x30 call Send movlw '.

5 PORTB. Delay ~ 200 mSec For Key Bounce 21 .42 movwf DUMMY1 decfsz DUMMY1.f goto $-1 return . Copy data from BITS register to RB4-RB7 . Send 8-bit data to LCD module .41 .4 BITS. . Unchange other bit of PORTB . Delay 5 millisecond movwf DUMMY2 D1 call Delay125 decfsz DUMMY2.4 PORTB. Delay 125 microsecond Delay5 movlw .6 PORTB.6 PORTB.6 BITS.5 PORTB.7 PORTB.7 .f goto D1 return Delay200 clrf DUMMY5 .f call Flip call Pulse call Delay125 return bcf btfsc bsf bcf btfsc bsf bcf btfsc bsf bcf btfsc bsf return PORTB. Send Upper 4-bit first and lower 4-bit following Flip . Pulse bsf E nop bcf E call Delay125 return Delay125 movlw .4 PORTB. Generate enable pluse for LCD . . Clear display .call Send movlw 0x01 call Send call Delay5 return Send movwf BITS call Flip call Pulse swapf BITS.5 BITS.7 BITS.

Clear 100's unit .C goto Less1 . Convert Hex to 3 Digit Decimal * . Subtract with 10 subwf DATA1. If < 10 then return incf NUM2.f $-1 DUMMY5. Subtract with 10 until the result lower 10 subwf DATA1.f $-3 .w btfss STATUS. Is it lower 10 ? goto Check Less1 movf DATA1. If > 10 then subtraction again .w movwf NUM1 clrf NUM3 Check2 movlw 0x0A subwf NUM2.w . If < 10.clrf decfsz goto decfsz goto return DUMMY6 DUMMY6.********************************************************************** Convert clrf NUM2 . .f . send data to 1's unit . and check until the result is lower 10 22 . Fisrt subtraction < 10 ? btfss STATUS.f movlw 0x0A subwf NUM2.f goto Check2 end .f . If < 10 then return .C return incf NUM3. Clear register of 10's unit Check movlw 0x0A .********************************************************************** . If > 10 then increase 10's unit movlw 0x0A . Test Again. 10's unit > 10 ? .

inc> errorlevel 0. low-voltage programming reference voltafe module. Digital Thermometer .-302 CBLOCK 0x20 DS_DAT DS_SIGN DUMMY0 DUMMY1 DUMMY2 DUMMY3 DUMMY4 SEND COUNT NUM1 NUM2 NUM3 DATA1 HALF endc 23 . It can be display 2 digit which you can applied to 3 digit Figure 1. WWW. Schematics of Digital Thermometers (PIC) For temperature sensor use IC DS1820 which The DS18S20 communicates over a 1-Wire bus.Digital Thermometer Digital Thermometers in this circuit design from microcontroller PIC16F628 of micrichip company.************************************************************************ .Guidecircuit.USART: Universal Synchronous Asynchronous Receiver Transmitter PWM (CCP : Capture Compare Pulse-width modulation module PIC16F628 For completed circuit of Digital Thermometers show in figure 1 .************************************************************************ list p=16f628 #include <p16f628. You can download data sheet from hardware Support Data. .com .Good point of PIC16F628 such as brown-out reset .

0x7f.#define DAT_PIN PORTB. Convert .5 #Define DQ PORTA.********************************************************************** Delay3 clrf DUMMY4 . 74595 CLK pin Table_ addwf PCL. ON DSP1 Display 24 .w HALF.0x6d.0x6f Start clrf movlw movwf bsf movlw movwf bcf call clrf bcf rrf rlf movwf call call goto PORTA 0x07 CMCON STATUS.6 Delay2 PORTB. Use 7-bit upper . Set port A for digital I/O .f goto DelayLp return Delay2 clrf DUMMY3 decfsz DUMMY3. Data for convert to decimal . Send data to LED 7 segments .0x7d.C DS_DAT.w Table_ HALF.RP0 b'00000110' PORTB STATUS. 74595 LATCH pin .0x07.4 #define CLK PORTB.0x4f.f goto $-1 return Disp movf call btfsc addlw call bcf call bsf NUM1.f dt 0x3f. Load data to DSP1 .6 .0 #define LATCH PORTB. Delay for scanning LED 7 segments .0x5b.RP0 RD_Temp HALF STATUS.0 org goto 0x000 Start . Show a half degree on dot-point LED . Display data delay . A Half digit . Read data from DS1820 . Store a half degree . Display data delay DelayLp call Disp decfsz DUMMY4. Set port B for displaying via LED 7 segments Main .0 0x80 Send_Dat PORTB.f DATA1 Convert Delay3 Main .********************************************************************** .0x06. Display On 7 Segment * . Convert data to decimal . 74595 DATA pin .0x66.

Set DQ to output bcf STATUS.f decfsz COUNT.7 bsf DAT_PIN Clock bsf CLK bcf CLK Rotate rlf SEND.Z .7 Delay2 PORTB.w Table_ Send_Dat PORTB.RP0 bcf DQ .movf call call bcf call bsf return NUM2.RP0 bsf DQ bcf STATUS. Z set = ready 25 . Macro for DS1820 * . Load data to DSP2 . Off DSP2 Send_Dat movwf SEND movlw 0x08 movwf COUNT Chk_Bit bcf DAT_PIN btfsc SEND.********************************************************************** RD_Temp call DS_Rx . Send data to LED 7 segments .f goto Chk_Bit Latch bsf LATCH bcf LATCH return . Rotate bit for sending next bit .********************************************************************** DQLOWmacro bcf DQ . Latch data for displaying . Check bit 7 "0" or "1" . Loop 8 times for sending 8-bit data . Send bit 7 to shift register . . Load data .********************************************************************** . Generate delay time . Clock pulse . On DSP2 . Convert .RP0 endm DQHIZ macro bsf STATUS. Set DQ to input . Check chip status addlw 0x01 btfss STATUS.7 . DS1820 1-Wire bus * . If no.RP0 endm PAUSE macro movlw movwf call endm DELAY DELAY DUMMY0 Delay5 . send bit again . DQ bit ready bsf STATUS.********************************************************************** . Test loop 8 times ? .

W is not zero = not ready . 8 times ? 26 . Restart . Response in W . Skip ROM movlw 0xcc call DS_Tx movlw 0x44 call DS_Tx Delay5 nop nop decfsz DUMMY0. Skip ROM .f STATUS. If Carry flag = "1" .C DQ 0x0d . Read 8-bit data .w return DS_Tx movwf movlw movwf Tx_Loop PAUSE rrf btfsc bsf PAUSE DQHIZ nop decfsz DUMMY2 0x08 DUMMY1 DQLOW 0x01 DUMMY2. Macro of DQ pin to low. 600 microcsecond delay . 70 microsecond delay DUMMY1.w andlw 0x01 movwf DUMMY1 PAUSE 0x3b movf DUMMY1. Define loop counter . Use RA0 only .return Get_Temp call DS_Reset movlw 0xcc call DS_Tx movlw call call movwf call 0xbe DS_Tx DS_Rx DS_DAT DS_Reset . Read response . Rotate data to Carry flag . Wait for response pulse (67 microsecond) . Test Carry flag . 300 microcsecond delay . Read scratch pad RAM of DS1820 .f .f goto Delay5 return DS_Reset DQLOW PAUSE 0x77 DQHIZ PAUSE 0x0c nop nop movf PORTA. set DQ to high . This is start bit . Transmission data . Start conversion . Prepare 8-bit counter for sending data . Delay for PAUSE macro . 10 microsecond delay .

increase 10's unit value movlw 0x0A . Recieve 8-bit data . Subtract with 10 until lower 10 and check result again goto Check movf DATA1. subwf DATA1.********************************************************************** end Less1 27 .f goto Check2 . Read again . No.C .goto Tx_Loop return DS_Rx movlw movwf Rx_Loop PAUSE DQHIZ nop nop movf andlw addlw rrf PAUSE decfsz goto movf return 0x08 DUMMY1 DQLOW 0x01 . send again .w 0x01 0xff DUMMY2.w .w . movwf NUM1 .w . Clear register of 10's unit Check movlw 0x0A . Move data bit 0 to DUMMY bit 7 . subwf DATA1. Check hundred unit Check2 movlw 0x0A subwf NUM2. If yes. If no. If no then return incf NUM3.w .********************************************************************** . 10 microsecond delay . Send data to 1's unit display clrf NUM3 . Macro of DQ pin to low. 60 microsecond delay .f movlw 0x0A . Convert Hex to Decimal(3 Digit) * .f Rx_Loop DUMMY2. If yes then return incf NUM2. Loop 8 times .f . btfss STATUS.********************************************************************** Convert clrf NUM2 . subtract again and check until the result is lower 10 subwf NUM2.f .C . Subtract with 10 until lower 10 btfss STATUS. Read data . Back to high for receiving PORTA. Get data bit 0 only .f 0x0b DUMMY1. Save data to W register . Check subtraction result lower 10 ? goto Less1 . 10's unit over 10 ? return . this is start bit . Move data bit 0 to Carry flag with addition method .

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->