I'm trying to write my "Hello world" program for PIC16F677.
I just want it to set all I/O pins high.
But the only pins that gets high are:
#4 - RA3 but it's input only, so I gues that's not set by my code.
#16 and #19 which are both marked as a comparator "+" input.
What am I missing?
I haven't read whole datasheet yet, so It's probably something obvious.
Hope someone can enlighten me.
I'm using HI-TECH Software\PICC\9.81\bin\picc.exe compiler.
Code:
#include<htc.h>
__CONFIG(MCLRE_OFF & CP_OFF & WDTE_OFF & FOSC_INTRCIO );
//clear off,code protect off, watchdog off, I'm not sure what should I set for osc. I'm using internal
void main()
{
//set all I/O ports as output
TRISA = 0;
TRISB = 0;
TRISC = 0;
//set all I/O ports high
PORTA = 1;
PORTB = 1;
PORTC = 1;
while(1)
{
//neverending story
}
}
Cannot help you with the actual C code, but if you google 'hi-tech c tutorials' you will find loads of help from microchip and other tutorials like gooligum etc.
Thanks!
Just noticed that binary notation works as well as hex.
Now I got some subquestions
What about decimal notation? How does compiler treat literal "1" from my initial code?
I guess it's int, and int is 16bit in hi-tech according to this document
Shouldn't then 0xFFFF also set all the bits high in 8bit register?
Yes. In addition all C rules of implicite type conversion apply as well. Writing 0xFFFF to a 8-Bit SFR simply ignores the upper 8 bits.
Writing bitmapped registers, e.g. IO ports at once is mainly done for initialization purposes. In later code execution, you mostly access single bits. The PIC bit access instructions actually perform a RMW (read-modify-write sequence), in some cases unwanted side effects may occur.
Looks like you could use some good tutorials, if you're not going to sleep, you might as well learn something.
So, I'm going to introduce you to some of the best PIC tutorials available online:
The lessons cover the baseline and midrange PIC architectures using assembly language and freely-available PIC C compilers.
The C tutorials actually use the Hi-Tech C Compiler.
**broken link removed**
The following tutorials build on the material covered in the midrange assembler tutorial series, showing how to implement the example applications from those lessons, using freely available PIC C compilers from HI-TECH Software.
**broken link removed**
Each covers a wide range of topics, from Basic I/O to ADC Peripherals.
I'm very impressed with Gooligum's tutorials, they are well documented, in PDF form and with good source code. I'm sure you will be impressed as well.
Thanks.
I'm actually in the middle of baseline lessons, really good indeed.
BTW.
I started my PIC programming with C, but I'm still considering going assembly way.
What do you guys think - is C enough? or is asm "must know"?
I was pretty comfy with PC assembler some years ago, but now I'm so much used to high level languages, that asm is a bit scarry
I could probably learn it in reasonable time, but do I really need to? Or is C equally good?
The only advantage of asm I can think of is the generated program size, is there any more? Are there many things that C won't do?
The Gooligum Tutorials are indeed a little know treasure.
Ah, yes, the Assembly vs C debate.
I believe the still both have a place and time. When you're coding for a device with only a few hundred bytes of RAM and a fee 'k' of Flash, there will be times to break out the assembler. The fusion of assembly and C code can be particularly handy in some situations. I would suggest taking the assembly versions of the Gooligum Tutorials, I can't foresee any detrimental situation, it can only help.
There are a great many algorithms available online coded in assembly, being able to read and understand them is a big plus.