Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Would someone like to comment on this code?

Status
Not open for further replies.

dukebound85

New Member
Hi all,
I am fairly new to programming and I am programming a PIC16F88 with Picbasic Pro. The purpose of this code is to...

When the unit is turned on, the lcd will display the ambient air temperature, via the A/D converion within the Port A.3 and a serout from portA.2. As long as the temperature is under a certian value, the buzzer will remain silent. Once it goes over a value, the buzzer will go off indefinitly. Also, once a switch is turned on, a fan will be driven by a motor and a led will confirm this. Once another switch is flipped on a stepper motor will go into action for as long as the switch is on. Notice I do not have the code for the stepper motor. This is for another day lol.

Basically, my question is am I on the right track? Learning how to program is difficult but I would like to learn. Thanks for any input on this matter

By the way, I have included 2 attachments.....one in text edit and another in Word. I use a Mac so I was unsure about textedit on windows
8)

Jonathan
 

dukebound85

New Member
Whoops guess it didnt attach

Here's the code

'Our program for Space Heater

DEFINE OSC 8 'Sets to 8Mhz
DEFINE ADC_CLOCK 64 'Set clock source (rc=64) WHATS THIS MEAN
DEFINE ADC_BITS 10 'Set number of bits in result
DEFINE ADC_SAMPLEUS 50 'Sets sampling time to 50 microseconds


temp VAR WORD 'create temp to store result

buzzer VAR PORTA.1 'renames PortA.4 as buzzer

onswitch VAR PORTB.2 'renames the ports as switches

stepswitch VAR PORTB.3

OSCCON.4=1
OSCCON.5=1
OSCCON.6=1

cmcon.0=1
cmcon.1=1
cmcon.2=1

cvrcon.6=0
cvrcon.7=0

ansel= %0000001 'Turns on channel 0



TRISB=%00110000 'sets PortB.2,3 as inputs and rest outputs
TRISA=%00001000 'as of now setting PORTA.3 as input
ADCON1=%00001000 'Sets PORTA.3 as analog input (right justified?)
ADCIN 0, temp 'Read channel 0 to temp

Pause 500 'Wait .5 sec



loop:
While (onswitch=1) 'lights up "on" led
Gosub Fan
Wend

ADCIN 0, temp
serout PORTA.2,2,[$0C] 'clears screen
serout PORTA.2,2 ["The Temperature is"] 'sends the string The Temperature is
serout PORTA.2,2 [$FE,$C0] 'moves the cursor to second line
serout PORTA.2,2,[DEC temp] 'displays the decimal value of temp OR SHOULD USE #?
Pause 500 'pauses display for .5 sec

If (DEC temp<30) 'So if temp is less that 30C, the buzzer doesn't sound
Then buzzer=0
Else buzzer=1 'Once the temp is greater than 30C, the buzzer goes off indefinitley
Endif

While (stepswitch=1) 'lights up "stepper" led OR would IF statements be better?
Gosub Stepper
Wend

Goto loop 'does it forever

End


Fan:
High PORTB.4 'this port is the port that goes into transistor for motor circuit
return

Stepper:
'Wait till lab
return
 

Oznog

Active Member
dukebound85 said:
As long as the temperature is under a certian value, the buzzer will remain silent. Once it goes over a value, the buzzer will go off indefinitly.

Me, I'd create a definite way to turn the damn buzzer off.
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top