PIC12F675 programming help

tracecom

Joined Apr 16, 2010
3,944
Well,my battery went out on my laptop,and it heated up.Now it's unusable.No hardware errors.
Strange.

Here's the code for the 12F629.

Rich (BB code):
' Name: Sima Code.pbp
' Compiler: PICBASIC PRO Compiler 3
' Assembler: MPASM
' Author: tracecom
' Target PIC: 12F629
' Hardware: CRH Breadboard
' Oscillator: 4MHz Internal 
' Description: Flashes an LED in a pattern determined by 3 switches 

' Device Configuration:
#IF __PROCESSOR__ = "12F629"
#config
cfg1 = _INTRC_OSC_NOCLKOUT  ; Internal oscillator
cfg1&= _WDT_ON              ; Watch Dog Timer Enabled
cfg1&= _PWRTE_OFF           ; Power-up Timer Disabled
cfg1&= _MCLRE_ON            ; Master Clear Reset Enabled
cfg1&= _BODEN_OFF           ; Brown-out Detect Disabled
cfg1&= _CP_OFF              ; Program memory code protection is disabled
cfg1&= _CPD_OFF             ; Data memory code protection is disabled
 __CONFIG  cfg1             ; Set the configuration bits
#ENDCONFIG
#else
 #MSG "Wrong microcontroller selected!"
#endif

' Defines:
Define OSCCAL_1K 1  ' Calibrate internal oscillator

' Aliases:
LED var GPIO.0  ' LED pin
SW1 var GPIO.1  ' Switch 1
SW2 var GPIO.2  ' Switch 2
SW3 var GPIO.4  ' Switch 3

' Variables:


' Register Initialization:
CMCON = 7            ' Analog comparators off
TRISIO = %00011110   ' GPIO 1, 2, 3 & 4 set as inputs; rest set as outputs

' Program Code:
Low LED ' Turn off LED connected to GPIO.0
  
mainloop:
    if (SW1 = 1) and (SW2 = 1) then gosub twoseconds
    if (SW1 = 1) and (SW3 = 1) then gosub twopulses
    Goto mainloop       ' Go back to mainloop

twoseconds:
    high LED    ' Turn on LED connected to GPIO.0
    Pause 2000  ' Delay for 2 seconds
    low LED     ' Turn off LED connected to GPIO.0
    return

twopulses:
    high LED    ' Turn on LED connected to GPIO.0
    pause 1000  ' Delay for 1 second  
    low LED     ' Turn off LED connected to GPIO.0
    pause 500   ' Delay for .5 seconds
    high LED    ' Turn on LED connected to GPIO.0
    pause 1000  ' Delay for 1 second 
    low LED     ' Turn off LED connected to GPIO.0
    return

End
Notice that SW3 is on GPIO.4.

You should also know that the code has not been tested beyond just the functions you asked for. It may crash unexpectedly without any warning.

BTW, what value of pull-downs are you using?
 
Last edited:

Thread Starter

koyaelektronic

Joined Aug 1, 2013
22
Hey Tracecom,

Thanks man,program works.Now I need to build ESD protection,because it is triggered.
Will post my progress.
Again thank you very much man.

Bance,
I didn't understand you,because english is not my native language,sorry.

Kind regards,
Sima
 
Top