Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC16F677 hello world

Status
Not open for further replies.

this

Member level 2
Joined
Apr 14, 2011
Messages
44
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Activity points
1,623
Hello world!

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
	}
}
 

Hi,

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.
 

The PORTx special function registers are Byte-wide ports. To set all port pins, write
Code:
PORTA = 0xFF;
 
  • Like
Reactions: this

    this

    Points: 2
    Helpful Answer Positive Rating
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?

TIA
 

Generally, decimal radix is default at most compilers.

+++
 

Got it now.
Obviously, I'm not setting separate bits, but whole register, so 255 would work, but not 1.

Sorry, I'm having hard time thinking, to much time spending learning electronics instead of sleeping :)
Thnks all.
 

Obviously, I'm not setting separate bits, but whole register, so 255 would work, but not 1.
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.
 
  • Like
Reactions: this

    this

    Points: 2
    Helpful Answer Positive Rating
Hi this,

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.

Ciao
 
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?

regards
 
Hi,

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.

And the debate rages on:

Assembly vs. C

Ciao
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top