View previous topic :: View next topic |
Author |
Message |
noob_programmer Guest
|
PIC16F877A programming |
Posted: Wed Mar 04, 2009 5:58 pm |
|
|
hi ,
I am trying to program a PIC16F877A.
I just started using it and am just testing the program.
Mmy program is simply:
Code: |
#include<16....>
#byte port_c = 7
void main{
set_tris_c(0);
port_c = 0;
byte value;
value = 0x00;
while(TRUE){
port_c = value;
}
} |
Basically this thing does nothing except to set port_c into output and put all output as 0.
But when I test the output it doesn't give me the 0 V I was looking for.
Can someone explain why?
Thanks for your help |
|
|
nostep
Joined: 04 Mar 2009 Posts: 16
|
|
Posted: Wed Mar 04, 2009 6:24 pm |
|
|
What are you getting as an output? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 04, 2009 6:28 pm |
|
|
Quote: | #include<16....>
#byte port_c = 7
void main{
set_tris_c(0);
port_c = 0;
byte value;
value = 0x00;
while(TRUE){
port_c = value;
}
} |
I tried to compile this with vs. 4.087, but it won't compile.
CCS doesn't permit variables to be declared in the middle of code.
You need to move it to the start of main(). What version are you using ? |
|
|
noob_programmer Guest
|
sorry |
Posted: Wed Mar 04, 2009 6:49 pm |
|
|
Sorry i didn't type it exactly like my code.
My intention was to say that
I tried to program it like that but my output measured by the oscilloscope gives me 2.5V out(which is neither here nor there).
the only stuff which i did was:
Code: | #byte port_c = 7
void main(){
port_c = 0;
while(TRUE){
//nothing important.
DELAY_MS(1000);
} |
}
Also I have another question.
I see online codes.
They have #byte port_a = 5 port_b=6?
Is there a specific code for this ?
Where do I get all these code ? |
|
|
noob_programmer Guest
|
|
Posted: Wed Mar 04, 2009 6:50 pm |
|
|
i forgot to add that i have set_tris_c(0) for output as well.
i'm using 2 computers and using another computer for the programming and this to surf the web.
so i am handtyping everything again.
sorry for the confusion. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 04, 2009 6:58 pm |
|
|
Use CCS functions. They will set the TRIS correctly and do the job.
Code: | void main()
{
output_c(0x00);
while(1);
} |
|
|
|
noob_programmer Guest
|
|
Posted: Wed Mar 04, 2009 7:19 pm |
|
|
this is my exact code
Code: |
#include <16F877A.h>
#USE DELAY (CLOCK=4000000)
#FUSES XT, NOWDT, NOPROTECT, NOPUT
void main(){
output_c(0xff);
while(1)
} |
nope
the output is still not 1 like what i wanted
thanks for helping |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 04, 2009 7:33 pm |
|
|
1. Always use the NOLVP fuse.
2. What is your compiler version ?
3. What board is your code being tested on ? Did you build it yourself
or did you buy it ? If you bought it, post the manufacturer and part
number. |
|
|
noob_programmer Guest
|
|
Posted: Wed Mar 04, 2009 9:58 pm |
|
|
Thanks for your help.
I managed to solve it.
I have another question right now.
Does anyone know what is the return value of get_rtcc()?
It says on the CCS manual returns the count value of the clock.
But what does it mean?
Is it measured in seconds? Or the oscillator count value?
I'm trying to time the return pulse my sensor is giving me. |
|
|
viknes1985
Joined: 11 Nov 2008 Posts: 24
|
it would be clock counter |
Posted: Thu Mar 05, 2009 2:45 am |
|
|
it would return oscillator counter.
for timer 0 (rtcc) : 0 - 255 |
|
|
Sydney
Joined: 13 Feb 2009 Posts: 71
|
|
Posted: Thu Mar 05, 2009 3:38 am |
|
|
noob_programmer wrote: | It says on the CCS manual returns the count value of the clock. |
Read the microchip data sheet too |
|
|
|