PDA

View Full Version : Timer does not work 12F675



Leonardo
- 21st September 2005, 14:54
Hello to all,

I am using PICBASIC COMPILER 1,45 and the following one I cosay does not work, I want to me to ignite the LED in pin2 by 1 minute and as soon as another minute is extinguished and continue the sequence but does not work to me, some suggestion.

I am using a PIC12F675.

Thanks


'code

Symbol Mi = B0
Symbol Se = B1

TOP:
Dir2 = 1 ' make Pins 2 and 1 outputs
Dir1 = 1

Pin2 = 0 ' turn off lamp - off or 1 minute
For Mi = 1 to 1 'minutes
For Se = 1 to 60 ' seconds
Pin1 = 1 ' test LED
Pause 500
Pin1 = 0
Pause 500
Next
Next

Pin2 = 1 ' turn lamp on - on for 1 minute

For Mi = 1 to 1 ' minutes
For Se = 1 to 60 ' seconds
Pin1 = 1
Pause 500
Pin1 = 0
Pause 500
Next
Next

GoTo TOP

CocaColaKid
- 21st September 2005, 19:03
There seems to be quite a few problems here that I can see.

Dir1 does not make pin 1 and input. The TRIS register is used to tell the ports direction.

I don't believe you can access a port by saying Pin1. You have to be a little more specific like GPIO.1 for instance.

What is the purpose of Mi? From what I can see it does nothing except consume resources.

CocaColaKid
- 21st September 2005, 19:15
Try this:



@ DEVICE PIC12F675, INTRC_OSC_NOCLKOUT
' System Clock Options (Internal)
@ DEVICE PIC12F675, WDT_ON
' Watchdog Timer
@ DEVICE PIC12F675, PWRT_ON
' Power-On Timer
@ DEVICE PIC12F675, MCLR_OFF
' Master Clear Options (Internal)
@ DEVICE PIC12F675, BOD_ON
' Brown-Out Detect
@ DEVICE PIC12F675, CPD_OFF
' Data Memory Code Protect
@ DEVICE PIC12F675, PROTECT_OFF
' Program Code Protection

DEFINE ADC_BITS 10 ' Set resolution of conversion
DEFINE ADC_CLOCK 3 ' Set clock source (x/FOSC or FRC)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time (in uS)

DEFINE OSCCAL_1K 1
DEFINE OSCCAL_2K 1

ANSEL = %00000000 ' Set analog ports to digital mode
ADCON0 = %10000001 ' Configure A/D channel
CMCON = %00000111 ' Turn off comparator
WPU = %00000000 ' Disable pull-ups
TRISIO = %00000 ' Set all I/O's to outputs


i var byte ' Counter variable
test_led var gpio.1
led var gpio.2

test_led = 0
led = 0

main:
for i = 0 to 59
test_led = 1
pause 500
test_led = 0
pause 500
next i
toggle led
goto main

Leonardo
- 21st September 2005, 19:53
Hello,

It gives the following error me

Thanks

Leonardo
- 21st September 2005, 20:04
Hello,
I have PICBASIC 1,45 and gives errors.

Thanks





Try this:



@ DEVICE PIC12F675, INTRC_OSC_NOCLKOUT
' System Clock Options (Internal)
@ DEVICE PIC12F675, WDT_ON
' Watchdog Timer
@ DEVICE PIC12F675, PWRT_ON
' Power-On Timer
@ DEVICE PIC12F675, MCLR_OFF
' Master Clear Options (Internal)
@ DEVICE PIC12F675, BOD_ON
' Brown-Out Detect
@ DEVICE PIC12F675, CPD_OFF
' Data Memory Code Protect
@ DEVICE PIC12F675, PROTECT_OFF
' Program Code Protection

DEFINE ADC_BITS 10 ' Set resolution of conversion
DEFINE ADC_CLOCK 3 ' Set clock source (x/FOSC or FRC)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time (in uS)

DEFINE OSCCAL_1K 1
DEFINE OSCCAL_2K 1

ANSEL = %00000000 ' Set analog ports to digital mode
ADCON0 = %10000001 ' Configure A/D channel
CMCON = %00000111 ' Turn off comparator
WPU = %00000000 ' Disable pull-ups
TRISIO = %00000 ' Set all I/O's to outputs


i var byte ' Counter variable
test_led var gpio.1
led var gpio.2

test_led = 0
led = 0

main:
for i = 0 to 59
test_led = 1
pause 500
test_led = 0
pause 500
next i
toggle led
goto main

CocaColaKid
- 21st September 2005, 20:13
Oops, the config fuses were set to PM assembler. This is the correct code to MPASM. Sorry about that.



@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON & _CPD_OFF & _CP_OFF
' System Clock Options (Internal)
' Watchdog Timer
' Power-On Timer
' Master Clear Options (Internal)
' Brown-Out Detect
' Data Memory Code Protect
' Program Code Protection


Are you sure your running v1.45 and not v2.45. That would have to be pretty old if that is correct.

Leonardo
- 21st September 2005, 20:40
Hello,

The code I cannot compile it with the PBC???.






Oops, the config fuses were set to PM assembler. This is the correct code to MPASM. Sorry about that.



@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON & _CPD_OFF & _CP_OFF
' System Clock Options (Internal)
' Watchdog Timer
' Power-On Timer
' Master Clear Options (Internal)
' Brown-Out Detect
' Data Memory Code Protect
' Program Code Protection


Are you sure your running v1.45 and not v2.45. That would have to be pretty old if that is correct.

Leonardo
- 21st September 2005, 20:41
I have version 1.45

Thanks

CocaColaKid
- 21st September 2005, 20:44
Oh, what a dummy I am. I thought you were using PBP. I'm not sure what the differences are since I use PBP and it works fine for me. I can't even try to compile it so I'm not too much help unfortunately.

Leonardo
- 21st September 2005, 20:46
Then I must compile it with PBP?.

Thanks

CocaColaKid
- 21st September 2005, 20:55
I'm not sure which commands it does not like since I'm not familiar with PBC. There should be much of a problem since the commands aren't overly complex that are used.

CocaColaKid
- 22nd September 2005, 12:26
I just thought of something else that might be the cause of your problems. You have to edit the 12F675.INC file located in the PBC folder and comment out this line by putting a ; in front of it.

__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _CP_OFF

mister_e
- 22nd September 2005, 21:12
As far as i'm aware of by reading
http://www.melabs.com/products/pbcis.htm
There's no ADCIN and direct acces to internal register, Variables are pre-defined B0... W1... and ,... and ... and

So you Must use PEEK POKE to write/read to/from internal register Adress and, and, and...

There's a huge difference between PBC and PBP. I don't have PBC here.. sorry :(

So only few code example @ melabs or other PBC user here could gives you some Hint. Look bellow
http://www.melabs.com/resources/samples.htm#pbc