The worst programmer ever to grace this forum - ME!
Ok, I've been on about 8 hours trying to get a damn LED to light using PICBAsic - nothing!
I have a PICkit 2 (the board comes with a PIC16F690), everything works fine with 'hello world' tutorial Microchip provide (which proves the chip & LED is fine). Assembly language make my brain spontaneously combust so I would like to learn a higher level language such as basic (which seems at least a little akin to DEC DCL...something I used about 10 years ago)...I'm beginning to wish I hadn't.
Right to my simple problem - more than anything in the world right now, I want to see that stupid little LED on my PICkit 2 low pin count board light up!
Most of the 'flash an led' example basic programs work on the PIC's Port A...now I thought it would be a simple case of changing the references conatined therein to PortC (the 4 leds on the Pickit board are attached to Port C)
But when I change not a lot happens!
I'm aware that the 16f690 has analogue ports turned on as default & Ive seen some mention that this can be remedied with a commands along these lines
ANSEL = 0
ANSELH = 0
but the microcode studio GUI doesn't seem to recognise those commands (I'm new to this interface but it seems to darken/bold commands it's happy with)
Could some one humour me here & cut/paste in the ludicrously simple basic code for PIC Basic Pro that I need to light an LED on portc.1 of my 16f690.
I can then put this all to rest & pour petrol over my pickit 2 whilst moonwalking backwards to "The eye of the Tiger".
FWIW, This is the latest code I've tried (based on this link http://www.digital-diy.net/16F%20Exa...LED's.aspx )....
Symbol LED_1 = PortC.0 ' Define a symbol in the program
TRISC.0 = 0 ' Make PORTC.0 an output
PORTC.0 = 0 ' and set it low (0V)
Main:
If LED_1 = 0 then ' Check the status of the LED
LED_1 = 1 ' and toggle it
Else
LED_1 = 0
Endif
DelaymS 1000 ' Delay for 1 second (compiler errors with this line - I guess the command isn't right!)
Goto Main ' Loop forever
Basic Schhmasic....
'F690 Registers and BUTTON Code
HankMcSpank,
I think the 'F690 is going to be my next favorite PIC. It has SO MUCH STUFF on it!
In other words, not a beginner PIC ( like the 16F628, F648, F87, F84(old and gray) )
There are ALOT of registers to learn how to use on this chip.
NOTE: something that used to trip me up when reading data sheets:
when you "SET" a value you change it to "1"
when you "CLEAR" a value you change it to "0"
so that if someone says "set the flag", it means to ONE, (1), HIGH
I only bring this up because you are new. The M-chip data sheets use this nomenclature all the time.
Also NOTE: The 16F690 Datasheet is your new best friend. All 306 pages, WOW. You might want to print out the pages with
the register descriptions for each "feature" so you know what CM1CON0, etc means. Adobe pages 34-37 are best. Also,
under the feature headings are listed all relevant registers that need to be set/cleared, usually near the end.
You might need to set ( or CLEAR) the following registers as well (some required in other PICs):
'Registers:
ANSEL = %00000000 ' clears the individual bits that select analog inputs (low register)
ANSELH = %00000000 ' clears the individual bits that select analog inputs (high register)
VRCON = %00000000 ' turns the Vref Module OFF by CLEARING bit7, 6, 4
'I use the binary format so I can easily set them later. I know it seems redundant when they are all 0's, but later....
'Bits Only:
CM1CON0.7 = 0 ' turns Comparator1 OFF by CLEARING bit7
CM2CON0.7 = 0 ' turns Comparator2 OFF by CLEARING bit7
ADCON0.0 = 0 ' turns the AD Converter OFF by CLEARING bit0
INTCON.0 = 0 ' clears the RABIF Flag (to 0), COULD be 1 on reset (unique to F690)
RCSTA.7 = 0 ' clears the SPEN bit ( SETTING SPEN DISABLES RB7 AS GENERAL PURPOSE! )
'note that there is an Errata Datasheet that mentions issues with SPEN, but only when using the Serial Hardware
'you might HAVE TO do this after clearing ANSEL/ANSELH
PORTA = %00000000 ' Clear the port register latches
PORTB = %00000000
PORTC = %00000000
TRISA = %11111111 ' Set or Clear the data direction registers
TRISB = %11111111
TRISC = %00000000
'FOR EXAMPLE: On the F628 and friends, you only need:
'CM1CON = 7 ' turns the comparators OFF by SETTING bits 0,1,2
'and the Port/Tris settings
'OK, now on to your code...
'The Button Command:
BUTTON 7, 0, 255, 0, B0, 1, Loop
'"7" is not a pin name.
'For buttons and LEDs, I use names like btnStart or btnUp, LEDFault, LEDStatus.
'But sometime I use PHYSICAL pin numbers on new chips that I'm learning. So try :
RB7pin10 VAR PortB.7
'I wouldn't use the term B0 as a variable, it is used so many other places (mainly STAMP) to denote PortB.0. Try:
Temp VAR BYTE
'Also, for the Jump To label you use "Loop", but I don't see it in your listing. Maybe you meant "Next", but you can't use that name.
'So Now:
Start:
LED1 = 0
Button RB7pin10, 0, 255, 0, Temp, 1, Blink
GOTO Start
Blink:
LED1 = 1
Pause 1000
GOTO Start
End
'I'm not at work so I can't test this until tomorrow.:o