Continue to Site

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.

my First Pic Project. Headlight Controller

Status
Not open for further replies.

grim

New Member
and no, it's not a "how do I........." thread:D

Well I have been through a lot of the tutorials, and sort of kind of probably understand, but its a bit like being a passenger in a car, you don't really learn the route until you drive it yourself, so I thought up a nice simple little project.

Walk-me-home headlights - you know the sort of thing, flash your headlights after you park and they stay on for a period of time, so you can see your front door lock etc.

It's pretty simple to do it with ordinary electronics, so using a pic needs to bring something else to the party, a programable delay. taa daaaar:D

# With the ignition off, a headlight flash will cause the lights to stay on for between 5 and 60 seconds - to the nearest second
# Programming to be achieved my working the headlights manually, and 'recording' the on time
# development using pickit2 and assembler
# pic16f690, as included with pickit2
# relay output

I will update the thread with ideas, jibberish, code etc as it procedes

so far the **broken link removed** is done. please forgive the non standard way I have drawn the Ignition checking - it pops out, checks, and pops back in again:D


now I am thinking as a development tool, it can start of by trickling through the process as i have shown, but then i can change it to use interupts and timers, once i understand them.
 
Why not cut it down abit, and ditch the programmable time feature, it will probably make life alot easier before you get into interrupts, I threw this together in basic, but should be easy to bit crunch with assembler

Code:
' Wait for the user to turn off the ignition, 
'  and the lights to be flicked on then off,
'  then turn them back on for a defined 
'  period of time
' Turning on the ignition at any time will reset 
'  the process (except during the delay period)

Device = 16F628
XTAL = 4

All_Digital = True

Symbol Lights_Input = PORTA.0
Symbol Ignition = PORTA.1
Symbol Light_Control = PORTA.2

TRISA = %00000011
PORTA = %00000000

[B]Main:[/B]
     Light_Control = 0
     If Ignition = 1 Then Goto Main

[B]Wait_For_Lights_On:[/B]
     While Lights_Input = 0
          If Lights_Input = 1 Then Goto Wait_For_Lights_Off
          If Ignition = 1 Then Goto Main
     Wend

[B]Wait_For_Lights_Off:[/B]
     While Lights_Input = 1
          If Lights_Input = 0 Then Goto Begin_Delay
          If Ignition = 1 Then Goto Main
     Wend     

[B]Begin_Delay:[/B]
     Light_Control = 1       ' Relay output
     Delayms 25000          ' Delay period
     Goto Main
 
gramo said:
Why not cut it down abit, and ditch the programmable time feature, it will probably make life alot easier before you get into interrupts, I threw this together in basic, but should be easy to bit crunch with assembler

Code:
' Wait for the user to turn off the ignition, 
'  and the lights to be flicked on then off,
'  then turn them back on for a defined 
'  period of time
' Turning on the ignition at any time will reset 
'  the process (except during the delay period)

Device = 16F628
XTAL = 4

All_Digital = True

Symbol Lights_Input = PORTA.0
Symbol Ignition = PORTA.1
Symbol Light_Control = PORTA.2

TRISA = %00000011
PORTA = %00000000

[B]Main:[/B]
     Light_Control = 0
     If Ignition = 1 Then Goto Main

[COLOR="RoyalBlue"][I][B]Wait_For_Lights_Off:[/B]
     While Lights_Input = 1
          If Ignition = 1 Then Goto Main
     Wend  [/I][/COLOR]
  
[B]Wait_For_Lights_On:[/B]
     While Lights_Input = 0
          If Lights_Input = 1 Then Goto Wait_For_Lights_Off
          If Ignition = 1 Then Goto Main
     Wend

[B]Wait_For_Lights_Off:[/B]
     While Lights_Input = 1
          If Lights_Input = 0 Then Goto Begin_Delay
          If Ignition = 1 Then Goto Main
     Wend     

[B]Begin_Delay:[/B]
     Light_Control = 1       ' Relay output
     Delayms 25000          ' Delay period
     Goto Main

I took the liberty of adding another Wait for lights off, near the start, otherwise if you arrive home, turn off the engine and then the lights, it will start the timer sequence.

was that written in Proton?


as for leaving out the programable timer, I agree that it simplifies things, but the point of using the pic to do it was the added functionalty.

eventually it will be a simple project, that uses interupts, timers, and stores a value. eventually:D

however i can read and understand the code you have put up there, so it's a start
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top