You are on page 1of 30

Temperature Controller

by Isaac Rotstein Box Hill Microcontrollers (BHM)

7 September 2012

Contents
1. 2. Summary Project Proposal
2.1 2.2 2.3 2.4 2.5 About the Client Company Employment Budget Project Summary Production Details

1 2

3.

Project Definition
3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 Client Company Personnel Supervisor Reporting Procedures Budget Main Suppliers Equipment and Environment Contingencies

4.

Project Scope
4.1 4.2 4.3 4.4 Timetable Parts List Materials And Components Full Budget

5.

Process Information
5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.10 5.11 5.12 5.13 Schematic Bought parts For Microcontroller Assembly Of PCB Testing Of PCB Mounting On Backboard Connecting LCD And Keypad Programming Program Testing Buy Parts for Temperature Sensor Add Sensor Program Sensor Testing the Temperature Sensor Additional 5.13.1 Data Logger 5.13.2 Active Heating and Cooling 5.13.3 Network Monitoring and Control

6. 7.

Testing and Troubleshooting Technical Data Used


7.1 7.2 Schematics Datasheets

x x

8. 9.

Results Appendices
9.1 9.2 9.3 9.4 Appendix 1: Appendix 2: Appendix 4: Appendix 2: 9.4.1 9.4.2 Schematic Additional Photos Distributors Locations Code Assembly Code (Microcontroller) Visual Basic code (Computer)

x x

10.

Bibliography

1.

Summary
1.1 This report covers the design, implementation and testing of a microcontroller-based Temperature Controller.

1.2

This report does not include a discussion of microcontroller fundamentals and electronic components used, but does assume prior knowledge of schematic interpretation, construction, microcontroller functionality and programming.

2. Project Proposal
2.1 2.2 2.3 2.4 Isaac Electronics requires the production of 35 temperature sensors for its infield work in occupational health and safety study in the mines of Irian Jara. Box Hill Microcontrollers (BHM) was employed on the 1st of February, 2007, to create a prototype of the requisite unit. If and when accepted, Box Hill Microcontrollers will complete the order. The prototype is to be completed by 21st June 2007, within a budget of $400.00. The Temperature Controller allows the user to set a minimum and maximum temperature which will be maintained within this range by the microcontroller. It comprises a visual display of current temperature and additional option to use with a computer-based data logger. Production of the temperature controller consists of: the building of an 89C66 microcontroller interface board; programming the microcontroller; construction of the temperature sensing circuit, and the programming of the computer-based data logger

2.5

3.

Project Definition
3.1 3.2 3.3 3.4 3.5 Client: Company: Personnel: Supervisor: Isaac Electronics Box Hill Microcontrollers 1 technician Isaac Rotstein Elizabeth Howard

Reporting Procedures 3.5.1 I. Rotstein to E. Howard 3.5.2 E. Howard to John Maddock (CEO, BHM) Budget: $400.00 Main Suppliers: Semtronics (See section 4.2 Project Scope/Parts List and Section 3.9.4 Project Definition/Alternative Suppliers) Equipment and Environment 3.8.1 Fully equipped work-station 3.8.2 Workshop OH & S standards Contingencies 3.9.1 Alternative Personnel J. Smith 3.9.2 Alternative Supervisor K. James 3.9.3 Budget Insurance See BHM policies and procedures/extended budgets 3.9.4 Alternative Suppliers Jaycar Electronics, Dick Smith electronics and DigiKey

3.6 3.7 3.8

3.9

4.

Project Scope
4.1 Timetable
Predicted Duration 1 1 1 8 1 1 1 2 15 15 2 22 15 24 64 Actual Duration 1 1 1 8 1 1 1 2 35 35 2 25 11 24 64

Table 1

Task Proposal Schematic Bought parts uC Assembly of PCB Testing of PCB Mounting Bought parts Temp Sensor Connecting LCD and Keypad Programming LCD+Keypad Program testing LCD+Keypad Add sensor Program Sensor Program Datalogger Test sensor Report

From 24/07/2006 24/07/2006 1/08/2006 7/08/2006 14/08/2006 26/10/2006 20/02/2007 16/04/2007 24/04/2007 24/04/2007 22/05/2007 23/05/2007 5/06/2007 23/05/2007 18/04/2007

To 24/07/2006 24/07/2006 1/08/2006 14/08/2006 14/08/2006 26/10/2006 20/02/2007 17/04/2007 28/05/2007 28/05/2007 23/05/2007 16/06/2007 15/06/2007 15/06/2007 20/06/2007

4.2
Table 2

Materials And Components


Quantity 1 1 1 1 2 2 1 1 1 1 1 3 1 1 1 1 8 1 1 2 1 2 1 1 1 Supplier Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics Semtronics $0.69 $0.85 $0.12 $0.98 $2.70 $0.70 $0.16 $0.17 $0.65 $0.07 $0.35 $0.03 $0.52 $7.27 $15.22 Price (each) $1.85 $4.50 $0.26 $0.06 $0.90 $0.08 $0.02 $0.02 $0.02 $0.40 Subtotal $1.85 $4.50 $0.26 $0.06 $1.80 $0.16 $0.02 $0.02 $0.02 $0.40 $0.91 $0.69 $2.55 $0.12 $0.98 $2.70 $0.70 $1.28 $0.17 $0.65 $0.14 $0.35 $0.06 $0.52 $7.27 $15.22 $3.34

Item LM35DZ Temperature Sensor ADC0831 8 Bit Serial ADC LM358N Dual OP-AMP BC557B PNP 45V 100mA 5K 25 Turn Trimmer Pot 5mm Red LED 10K 0.25W Carbon Resistor 5% 150R 0.25W Carbon Resistor 5% 4K7 0.25W Carbon Resistor 5% 10uF 35V Tantalum Capacitor GST DB9 Right Angle Female Socket Machined Socket Strip DIL IC Socket PLCC Socket Min Right Angle Toggle Swtich Push Button PCB 35V 12.5TR Tantalum Capacitor Resistor Network Crystal Ceramic Disc Capacitor LM7805 5V Voltage Regulator 3K9 0.25W Carbon Resistor 5% 35V 2.5 Tantalum Capacitor 4x4 Alphanumeric Keypad 16 Caracters x 2 Lines Backlit LCD GST

P98C668HBA Microcontroller 68.09W Peltier Module 28cm x 17cm Heatsink (can use 2xH3408) Heat Transfer Compound 17cm 12V Fan IRF540N N-Channel MOSFET IRF9540N P-Channel MOSFET UCC27321 Inverting Mosfet Driver UCC27322 Non-Inverting Mosfet Driver

1 1 1 1 1 2 2 1 1

BHT Jaycar Electronics Dick Smith Electronics Dick Smith Electronics RS Components (Radiospares) RS Components (Radiospares) RS Components (Radiospares) Digi-Key Digi-Key

$25.00 $17.95 $47.98 $3.79 $151.00 $9.02 $8.22 $2.96 $2.96 TOTAL:

$25.00 $17.95 $47.98 $3.79 $151.00 $18.04 $16.44 $2.96 $2.96 $332.86

4.3

Full Budget 4.3.1 Parts 4.3.2 Communications 4.3.3 Travel 4.3.4 Office Supplies

$332.86 $ 4.00 $15.00 $ 3.00

5.

Process Information
5.1 Schematic A schematic was provided by Box Hill Microcontrollers which details the construction of the Microcontroller PCB (See 9.1 Appendices/Appendix 1: Schematic. Note: this diagram does not represent the original schematic given). Bought Parts for Microcontroller The parts required to construct the PCB as well as a 16x2 LCD screen and 4x4 keypad were bought from Semtronics Assembly of PCB The components were placed into the PCB and soldered into place. Some holes were enlarged via a drill in order to facilitate particular devices. Pins were added to connect power and optional external switches
Fig 1. Microcontroller PCB fully assembled

. 5.2

5.3

5.4

Testing Of PCB Power was applied to the circuit and voltage slowly increased to check for excessive current use. The board was connected via a serial cable to a computer and a simple test program was downloaded to the microcontroller. A digital multimeter was connected to an output pin to test for oscillations. Mounting On Backboard The microcontroller board, LCD screen and keypad were mounted on a wooden backboard via standoffs. A breadboard was added to facilitate additional circuitry to be interfaced with.
Fig 2. Microcontroller; LCD; Keypad and Breadboard mounted on wooden base.

5.5

5.6

Connecting LCD And Keypad The LCD screen and keypad were connected to the microcontroller, each via a different port. Programming A program was written in order to test the functionality of the LCD screen and keypad. Program Testing The program was downloaded onto the microcontroller and executed to validate operation. Buy Parts for Temperature Sensor All components required to construct the temperature sensor circuit were bought from Semtronics. Add Sensor The temperature sensing circuit was then connected to the microcontroller to allow the microcontroller to interface with the analogue to digital converter. Program Sensor A temporary program was written in order to verify operation of the analogue to digital converter. After verifying its operation, all code for interfacing the LCD, keypad, LCD and analogue to digital converter (ADC) was combined and modified for setting and displaying temperatures.

5.7

5.8

5.9

5.10

5.11

5.12

Testing The Temperature Sensor The calibration potentiometer was adjusted to 1.28 Volts to scale the temperature between 0 and 128C Operation of the temperature sensor was verified and program altered until correct operation was obtained. Additional 5.13.1 Data Logger A computer-based data logger was written in order to graph the current temperature and control temperature limits.
Fig 3. The computer-based data logger

5.13

5.13.2 Active Heating and Cooling A peltier-based heat pump device was mounted on a fan cooled heatsink Additional circuitry was designed and added to interface the microcontroller with the peltier so that it could heat and cool. Testing of the entire setup was performed and verified.
Fig 4. The completed board with peltier control circuitry

Fig 5. 17cm diameter fan used to maintain heatsink temperature

Fig 6. Peltier module mounted with heat transfer compound to the heatsink

5.13.3

Network Monitoring And Control A network controlled version of the data logger was written to allow remote monitoring and controlling.
Fig 7. The network client version of the data logger and control software

6.

Testing and Troubleshooting


Debugging of the microcontroller code, network server data logger code and network client data logger code was performed until changes on either one of these were reflected on all devices. For high power peltiers, the MOSFETs which make up the H-Bridge had to be mounted on an additional heatsink (Obtained from Dick Smith Electronics, Currently obsolete. See Jaycar part number HH8560 for equivalent)

7.

Technical data used


-Microcontroller board schematic -Temperature sensor schematic -Additional circuit schematic -Component datasheets -LCD screen -Keypad -ADC0831 (ADC) -LM741 (OP-AMP) -LM35 (temperature sensor) -IRF540 (N-Channel MOSFET) -IRF940 (P-Channel MOSFET) -BC557B (PNP transistor) -UCC27321 (Non-Inverting MOSFET Gate Driver) -UCC27322 (Inverting MOSFET Gate Driver)

8.

Results

Fig 8. The LCD display as the program runs

Fig 9. A test run of the data logger while maintaining the temperature of a partially filled cup of water between a lower and upper limit

9.

Appendices
9.1 Appendix 1: Schematic

Fig 10. The final combined schematic

9.2

Appendix 2: Additional Photos

Fig 11. Peltier; Heatsink, and fan setup (air flow from bottom to top and out through heatsink sides)

Fig 12. Cup of water with stirer placed on the peltier. Temperature Sensor is electrically sealed and immersed in the water

Fig 13. The stirer in action

9.3

Appendix 4: Distributors Locations: 9.3.1 Semtronics 19B Queen Street Nunawading Victoria 3131 Australia MC BOX 555 Eastern Mail Centre Victoria 3110 9.3.2 Dick Smith Electronics Shop 1 Centro Box Hill 1 Main Street Box Hill VIC 3128 9.3.3 Jaycar Electronics 141A Maroondah Highway Ringwood Victoria, Australia 9.3.4 RS Components 294 Salmon St Port Melbourne 3207 Digi-Key Online only: www.digikey.com

9.4

Appendix 2: Code 9.4.1 Assembly Code For The Microcontroller

$mod652 ; ; **** Equates and Setup **** ; rs bit p0.1 rw bit p0.2 e bit p0.3 fn_reg data 30h hashflg bit 20h.0 flag1 bit 20h.1 flag2 bit 20h.2 minreg data 31h maxreg data 32h pwrflg1 data 33h pwrflg2 data 34h A2Dbuf data 35h cs bit p1.0 clk bit p1.1 do bit p1.2 ; ;************************ ; Main program ;************************ ; org 0 mov S0CON,#50h ;serial mode 1, receive enable mov TMOD,#20h ;timer 1 8 bit auto reload mov TH1,#0FDh ;TH1=256-((11059200/192)/19200) for baud rate of 19200 ;mov TH1,#208 ;TH1=256-((11059200/192)/1200) for baud rate of 1200 setb TR1 ;set timer1 run bit mov a,pwrflg1 cjne a,#55h,cold mov a,pwrflg2 cjne a,#0aah,cold jmp warm cold: mov sp,#0e8h ; set stack in shadow RAM call lcdrst call lcdinit mov maxreg,#23h mov minreg,#18h mov pwrflg1,#55h mov pwrflg2,#0aah mov dptr,#table0 mov r0,#40h call blkmov mov r0,#40h call display mov r6,#200 call wait

mov r6,#200 call wait warm: mov fn_reg,#00h setb hashflg mov dptr,#table1 mov r0,#40h call blkmov mov r1,#fn_reg mov r0,#4eh call puts back: push 00 ; save r0 pointer value mov r0,#40h call display pop 00 ; retrieve r0 pointer value call getkey cjne a,#'#',onw1 jmp hashtst onw1: cjne a,#'*',onw2 jmp onw3 onw2: call ripple onw3: jmp back ; hashtst:cpl hashflg jnb hashflg,test0 mov dptr,#table1 mov r0,#40h call blkmov mov r1,#fn_reg mov r0,#4eh call puts jmp back ; test0: mov a,fn_reg cjne a,#00h,test1 ;if not funtion 0 jump to next mov dptr,#table4 ;function 0 mov r0,#40h call blkmov mov r1,#minreg mov r0,#5ch call puts jmp back test1: mov a,fn_reg cjne a,#01h,test2 mov dptr,#table3 mov r0,#40h call blkmov mov r1,#maxreg mov r0,#5ch call puts jmp back ;if not funtion 1 jump to next ;function 1

test2: mov a,fn_reg cjne a,#02h,nofunc ;if not funtion 2 jump to nofunc

clr c

;function 2

test:

mov a,maxreg cjne a,minreg,test ;carry flag is set if dest<src jmp equal ;equal jc fault ;fault (if maxreg<minreg) jmp noprob0 ;ok (if maxreg>minreg) ;maxreg<minreg message

fault: mov dptr,#table6 mov r0,#40h call blkmov mov r0,#40h call display mov r6,#200 call wait mov r6,#200 call wait mov fn_reg,#00h jmp test0 equal: mov dptr,#table7 mov r0,#40h call blkmov mov r0,#40h call display mov r6,#200 call wait mov r6,#200 call wait mov fn_reg,#00h jmp test0

;equal message

nofunc: mov dptr,#table8 ;invalid function message mov r0,#40h ;internal ram call blkmov mov r0,#40h ;reload internal ram position since blkmov incremented it mov r1,#fn_reg mov r0,#79 call puts mov r0,#40h call display mov r6,#200 ;wait 2 seconds call wait mov r6,#200 call wait jmp warm noprob0:;-------------push acc mov a,minreg anl a,#0Fh rl a rl a rl a

rl a orl a,#00000001b mov S0BUF,a jnb TI,$ clr TI mov a,minreg anl a,#0F0h orl a,#00001001b mov S0BUF,a jnb TI,$ clr TI ;-------------mov a,maxreg anl a,#0Fh rl a rl a rl a rl a orl a,#00000010b mov S0BUF,a jnb TI,$ clr TI mov a,maxreg anl a,#0F0h orl a,#00001010b mov S0BUF,a jnb TI,$ clr TI pop acc ;-------------noprob: mov dptr,#table5 mov r0,#40h call blkmov mov r1,#minreg mov r0,#45h call puts mov r1,#maxreg mov r0,#4dh jb p1.3,U mov 4fh,#'O' jmp next mov 4fh,#'U'

;LS minreg nibble into serial buffer ;wait for buffer to empty

;MS minreg nibble into serial buffer ;wait for buffer to empty

;LS minreg nibble into serial buffer ;wait for buffer to empty

;MS minreg nibble into serial buffer ;wait for buffer to empty

;check if to display U or O

U:

next: call puts test2a: mov p2,#011111011b ;ground col. jb p2.7,next2 ;test for ungrounded row on hash key mov r6,#30 ;if grounded, hash key pressed, 150ms debounce call wait jnb p2.7,$ ;wait for key up (grounded)

ljmp warm next2: jnb RI,nodata ;if no byte from serial port then skip mov minreg,S0BUF ;read the tmin byte from the serial port clr RI jnb RI,$ ;wait for RI flag to be set (for second byte) mov maxreg,S0BUF ;read the tmax byte from the serial port clr RI ;send data in the form DDDDNCCC D=data N=nibble C=commnad ;C=1, adc C=2, minreg C=3 maxreg N=0, LS N=1, MS nodata: mov r0,#16 ;send 16 samples to the serial port (will be averaged) sendspl:call A2D ;-------------push acc mov A2Dbuf,a anl a,#0Fh rl a rl a rl a rl a mov S0BUF,a ;LS data nibble into serial buffer jnb TI,$ ;wait for buffer to empty clr TI mov a,A2Dbuf anl a,#0F0h orl a,#00001000b mov S0BUF,a jnb TI,$ clr TI pop acc ;-------------djnz r0,sendspl

;MS data nibble into serial buffer ;wait for buffer to empty

mov r0,#5ch call conv1 mov r0,#40h call display mov a,A2Dbuf call conv2 ;mov r6,#100 ;call wait clr c subb a,maxreg jnc otemp mov a,A2Dbuf call conv2 clr c subb a,minreg jc utemp jmp noprob otemp: clr p1.3 ; turn on LED

jmp noprob utemp: setb p1.3 ; turn off LED jmp noprob ;...................................... ; Subroutines ;...................................... ; ; A2D routine returns with converted value in Acc ; A2D: clr clk clr cs mov r2,#9 A2D1: setb clk nop nop clr clk nop ; clock to valid data delay mov c,do rlc a djnz r2,A2D1 setb cs setb clk ret ; ; conv1 routine converts number in acc into 3 bcd digits ; xxx.x format, the lsb x stored @r0. Range 0 to 127.5 ; conv1: clr flag1 mov b,#2 div ab mov r2,b cjne r2,#1,fwd1 mov @r0,#'5' jmp fwd2 fwd1: mov @r0,#'0' fwd2: dec r0 mov @r0,#'.' dec r0 dec r0 dec r0 mov b,#100 div ab cjne a,#0,fwd3 mov @r0,#' ' setb flag1 jmp fwd4 fwd3: add a,#30h mov @r0,a fwd4: inc r0 mov a,b mov b,#10 div ab cjne a,#0,fwd5

jb flag1,over mov @r0,#'0' jmp fwd6 over: mov @r0,#' ' jmp fwd6 fwd5: add a,#30h mov @r0,a fwd6: inc r0 mov a,b add a,#30h mov @r0,a ret ; ; conv2 routine divides Acc by 2 ; converts it into 2 "pseudo BCD" digits ; conv2: mov b,#2 div ab mov b,#10 div ab swap a add a,b ret ; ; getkey routine returns with keypress in acc ; getkey: mov p2,#11111000b ; cols low, rows high jnb p2.4,onw ; if any row low we've got a keypress jnb p2.5,onw jnb p2.6,onw jnb p2.7,onw jmp getkey ; no key pressed onw: mov r6,#4 call wait jnb p2.4,tst1 ; if any key still low its a valid keypress jnb p2.5,tst1 jnb p2.6,tst1 jnb p2.7,tst1 jmp getkey ; no key pressed or invalid keypress tst1: mov p2,#11111110b ; ground left hand col only jb p2.4,tst2 ; if it's not key 1 mov a,#'1' ; if it is key 1 jmp exit tst2: jb p2.5,tst3 ; if it's not key 4 mov a,#'4' ; if it is key 4 jmp exit tst3: jb p2.6,tst4 ; if it's not key 7 mov a,#'7' ; if it is key 7 jmp exit tst4: jb p2.7,tst5 mov a,#'*' jmp exit tst5: mov p2,#11111101b ; ground next column jb p2.4,tst6

mov a,#'2' jmp exit tst6: jb p2.5,tst7 mov a,#'5' jmp exit tst7: jb p2.6,tst8 mov a,#'8' jmp exit tst8: jb p2.7,tst9 mov a,#'0' jmp exit tst9: mov p2,#11111011b ; ground next column jb p2.4,tst10 mov a,#'3' jmp exit tst10: jb p2.5,tst11 mov a,#'6' jmp exit tst11: jb p2.6,tst12 mov a,#'9' jmp exit tst12: jb p2.7,exit mov a,#'#' exit: mov r6,#30 ;debounce call wait wait4up:mov p2,#11111000b jnb p2.4,wait4up jnb p2.5,wait4up jnb p2.6,wait4up jnb p2.7,wait4up ;wait for key up before returning

ret ; ; ripple routine ripples the last keypress into ; RAM location pointed to by r1 and calls puts to ; put it into the relevant screen locations. ; ripple: xch a,@r1 swap a xch a,@r1 xchd a,@r1 call puts ret ; ; puts routine puts present numeric contents of RAM location, ; pointed to by r1, into LCD RAM image positions pointed ; to by r0,r0-1. R0 is unaffected, as is R1. Assumes exising ; ascii numbers (top nibble 3) at these locations. ; puts: mov a,@r1 xchd a,@r0 mov a,@r1 swap a

dec r0 xchd a,@r0 inc r0 ; restore R0 to orig value ret ; ; blockmove subroutine (blkmov) moves the message table ; pointed to by DPTR up to RAM pointed to by r0 ; blkmov: mov r7,#32 ; 32 total chars in table blk2: mov a,#00h movc a,@a+dptr mov @r0,a inc dptr inc r0 djnz r7,blk2 ret ; ; display routine updates screen from RAM image pointed to by r0 ; display:push acc mov a,#80h ; set up LCD DD RAM addr for 1st line call disp2 mov a,#0c0h ; 2nd line call disp2 pop acc ret disp2: call com call busy mov r7,#16 ; byte counter disp3: mov a,@r0 ; get data from RAM call dat call busy inc r0 djnz r7,disp3 ret ; string routine sends 8 bytes to LCD as data ; string: mov r2,#8 string1:mov a,#0 movc a,@a+dptr call dat call busy inc dptr djnz r2,string1 ret ; 'com' the contents of acc are sent ; to the lcd as a command com: clr rw clr rs

mov b,a anl p0,#0fh anl a,#0f0h orl p0,a setb e clr e anl p0,#0fh mov a,b swap a anl a,#0f0h orl p0,a setb e clr e ret ; 'dat' the contents of acc are sent ; to the lcd as data dat: clr rw setb rs mov b,a anl p0,#0fh anl a,#0f0h orl p0,a setb e clr e anl p0,#0fh mov a,b swap a anl a,#0f0h orl p0,a setb e clr e ret

; 'busy' waits until the lcd has ; finished before it returns busy: ;orl p0,#0f0h ; top 4 bits of p1 are I/P ;clr rs ;setb rw ;setb e ;jb p0.7,$ ; mov a,p1 ;clr e ;setb e ; 2nd read ;clr e mov r6,#1 call wait ret ; 'lcdrst' does a soft reset of the lcd ; to make sure it is reset

lcdrst: mov r6,#2 call wait ; wait 10ms mov r2,#3 rst1: mov r6,#1 ; set 5ms delay call wait clr rs clr rw clr p0.7 clr p0.6 orl p0,#30h ; send 30h 3 times setb e clr e djnz r2,rst1 clr p0.4 ; send 20h once setb e clr e mov r6,#1 call wait ; wait another 5ms ret ;'lcdinit' initialises the lcd ; lcdinit:mov a,#28h ; function set for 4 bits data call com call busy mov a,#0ch call com call busy mov a,#06h call com call busy mov a,#01h call com call busy ret ; ;'wait' produces 5msec delay multiplied ;by the value in r6 in 89C66X CPU's (6 clock mode) ; wait: mov r4,#50 ; originally 25 wait1: mov r5,#91 djnz r5,$ djnz r4,wait1 djnz r6,wait ret ;...................................... ; tables ;...................................... ; table0: db '89C66 Powered Up' db 'Please Select fn' table1: db ' Function no 00 '

db ' # is enter

'

table3: db 'Enter Max Value ' db ' Currently 23',0dfh,43h,20h table4: db 'Enter Min Value ' db ' Currently 18',0dfh,43h,20h table5: db 'Min 22',0dfh,' Max 22',0dfh,20h db 'Current 25.0',0dfh,43h,20h table6:db 'Max Value Must ' db 'Be > Min Value! ' table7: db 'Error: Equal db ' ' '

table8: db 'No Funct. For 00' db 'Please Reselect ' end 9.4.2 Visual Basic code for the computer-based data logger/controller (Original non-network version) Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Dim inputdata As Long Dim x As Long Dim tmin As Double Dim tmax As Double Dim tsetmin As Double Dim tsetmax As Double Dim voltage As Double Dim temperature As Double Dim graphinterval As Double Dim t As Double Dim samples As Long Dim graph(750) As Double Dim serialbyte As Long Dim prevserialbyte As Long Dim serialbytedata As Long Private Sub Command1_Click() If MSComm1.PortOpen = False Then If IsNumeric(Text3.Text) And IsNumeric(Text4.Text) Then MSComm1.CommPort = CLng(Text3.Text) MSComm1.Settings = Text4.Text + ",n,8,1" If MSComm1.PortOpen = False Then MSComm1.PortOpen = True t = Timer Else MsgBox "non numeric" End If

Else MsgBox "already connected" End If End Sub Private Sub Command2_Click() If MSComm1.PortOpen = True Then MSComm1.PortOpen = False End Sub Private Sub Command3_Click() If IsNumeric(Text1.Text) And IsNumeric(Text2.Text) And IsNumeric(Text5.Text) Then If CDbl(Text2.Text) > CDbl(Text1.Text) Then tmin = CDbl(Text1.Text) tmax = CDbl(Text2.Text) graphinterval = CSng(Text5.Text) Call markersandgrid Else MsgBox "max must be greater then min" End If Else MsgBox "non numeric" End If End Sub Private Sub Command4_Click() If MSComm1.PortOpen = True Then If IsNumeric(Text6.Text) And IsNumeric(Text7.Text) Then tsetmin = Round(CLng(Text7.Text), 0) 'min tsetmax = Round(CLng(Text6.Text), 0) 'max If tsetmin >= 0 And tsetmin <= 98 And tsetmax >= 1 And tsetmax <= 98 Then If tsetmax > tsetmin Then tens = tsetmin \ 10 PBCD = (tens * 16) + (tsetmin - (tens * 10)) MSComm1.Output = Chr(PBCD) Sleep (1000) 'wait for the first byte to be recieved and processed and ready to wait for next tens = tsetmax \ 10 PBCD = (tens * 16) + (tsetmax - (tens * 10)) MSComm1.Output = Chr(PBCD) Call markersandgrid Else MsgBox "max must be greater then min" End If Else MsgBox "out of range. Use 0 to 99" End If Else MsgBox "non numeric"

End If Else MsgBox "not connected" End If End Sub Private Sub Form_Load() tmin = CDbl(Text1.Text) tmax = CDbl(Text2.Text) tsetmin = CLng(Text7.Text) 'min tsetmax = CLng(Text6.Text) 'max graphinterval = CSng(Text5.Text) Call markersandgrid End Sub Private Sub Form_Unload(Cancel As Integer) If MSComm1.PortOpen = True Then MSComm1.PortOpen = False End End Sub Private Sub MSComm1_OnComm() 'data in the form DDDDNCCC D=data N=nibble C=commnad 'C=1, adc C=2, minreg C=3 maxreg N=0, LS N=1, MS dbyte = MSComm1.Input If dbyte <> "" Then prevserialbyte = serialbyte serialbyte = Asc(dbyte) If ((prevserialbyte And 8) = 0) And ((serialbyte And 8) = 8) Then 'if 2 valid sequential nibbles have arrived serialbytedata = ((prevserialbyte And 240) \ 16) + (serialbyte And 240) If ((prevserialbyte And 7) = 0) And ((serialbyte And 7) = 0) Then 'type=data '-----------------------------------------------------------------------------inputdata = inputdata + serialbytedata samples = samples + 1 If Timer - t >= graphinterval Then t = Timer voltage = (inputdata / samples) * 1.28 / 255 temperature = voltage * 100 graph(x) = temperature Label1.Caption = CStr(Format(Round(temperature, 1), "0.0")) + "C" If x = 0 Then Picture1.PSet (x, 484 - (((temperature - tmin) / (tmax - tmin)) * 484)), RGB(0, 255, 255) Else Picture1.Line -(x, 484 - (((temperature - tmin) / (tmax - tmin)) * 484)), RGB(0, 255, 255) End If x=x+1

If x > 750 Then x=0 Picture1.Cls Call markersandgrid End If inputdata = 0 samples = 0 End If DoEvents '-----------------------------------------------------------------------------End If If ((prevserialbyte And 7) = 1) And ((serialbyte And 7) = 1) Then 'type=minreg '-----------------------------------------------------------------------------tens = ((serialbytedata And 240) \ 16) * 10 tsetmin = tens + (serialbytedata And 15) Text7.Text = tsetmin Call markersandgrid '-----------------------------------------------------------------------------End If If ((prevserialbyte And 7) = 2) And ((serialbyte And 7) = 2) Then 'type=maxreg '-----------------------------------------------------------------------------tens = ((serialbytedata And 240) \ 16) * 10 tsetmax = tens + (serialbytedata And 15) Text6.Text = tsetmax Call markersandgrid '-----------------------------------------------------------------------------End If End If End If End Sub Private Sub grid() 'x grid For I = 0 To 750 Step 75 Picture1.Line (I, 0)-(I, 484), RGB(128, 128, 128) Next I 'y grid j=0 For I = 0 To 484 Step 484 / 10 Picture1.Line (0, I)-(750, I), RGB(128, 128, 128) Label12(j).Caption = Format(((j / 10) * (tmax - tmin)) + tmin, "0.0") + "C" j=j+1 Next I End Sub Private Sub markersandgrid() Picture1.Cls Call grid

'min I = 484 - (((tsetmin - tmin) / (tmax - tmin)) * 484) Picture1.Line (0, I)-(750, I), RGB(0, 0, 255) 'max I = 484 - (((tsetmax - tmin) / (tmax - tmin)) * 484) Picture1.Line (0, I)-(750, I), RGB(255, 0, 0) 'redraw graph For I = 0 To x If I = 0 Then Picture1.PSet (I - 1, 484 - (((graph(I) - tmin) / (tmax - tmin)) * 484)), RGB(0, 255, 255) Else Picture1.Line -(I - 1, 484 - (((graph(I - 1) - tmin) / (tmax - tmin)) * 484)), RGB(0, 255, 255) End If Next I End Sub

10. Bibliography
Wemm,J. 2005 Lecture Notes, Box Hill Institute Datasheets (See section 7 Technical data used/Component datasheets)

You might also like