Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
If you scroll down and look at the address 0x7F9 you'll see more data which is the actual program location. C compilers sometimes create strange assembly code.:02000000F92FD6
:0E0FF200FF3083120313860083168601FF2F43
:00000001FF
kchriste said:You should also have pullups on the unused pins or program them as outputs
#include<pic.h>
#include<htc.h>
__CONFIG(0x3f79);
void main()
{
PORTB = 0xFF;
TRISB = 0x00;
while(1);
}
#include<pic.h>
#include<htc.h>
__CONFIG(0x3f79);
void delay(void);
void main()
{
TRISB = 0x00;
while(1){
PORTB = 0xFF;
delay();
PORTB = 0x00;
delay();
}
}
void delay(void){
int i;
for(i=0;i<15000;i++);
}
As pointed out, 4 MHz crytals use 'XT' for oscillator configuration instead of 'HS', or the oscillator might not start (from my experience). Added configuration labels for Hi-Tech PICC with your setup.DMW said:i have set mine to:
Oscillator = HS
Watchdog timer = off
Power-up timer = on
Brownout detect = off
Low voltage program = disable
Flash program write = write protection off
Data EE code protect = off
Code protect = off
HEX: 3F32
4Mhz crystal with 2 x 22pf capacitors
#include <htc.h>
__CONFIG ( XT & WDTDIS & PWRTEN & BORDIS & LVPDIS & UNPROTECT );
void main(){
PORTB = 0; // clear PORTB
TRISB = 0xFE; // RB0 is output
RB0 = 1; // set RB0
while(1); // loop forever
}
#include<pic.h>
#include<htc.h>
__CONFIG(0x3f79);
void delay(void);
void main()
{
TRISB = 0x00;
while(1){
PORTB = 0xFF;
delay();
PORTB = 0x00;
delay();
}
}
void delay(void){
int i;
for(i=0;i<15000;i++);
}
This header makes your code more portable. You don't need to include <pic.h>, because the header file htc.h determines which compiler is running and include the specific header file (pic.h, pic18.h, etc.)DMW said:btw what does
#include<htc.h>
do? that might of been whats missing.
DMW said:ok after abit of testing it turns out the error was the configuration bits
DMW said:I was about to look this up, but seeing as im posting here anyway, if i want to set a specific port as an 1 or 0 without changing any of the other ports within a register output, how is it done
example, i want to change B3 from 0 to 1 say without redefining the entire register for B,
can you do it like arrays?
PORTB[3] = 1?
because that's not working for me :S
You should also have pullups on the unused pins or program them as outputs
You mean the PIC won't draw extra current when all the input pins are floating at around 1/2 Vdd? Always thought that it would. Maybe I'll experiment with this later.Nigel Goodwin said:It makes no difference whatsoever, it's a fallacy based on that requirement for CMOS logic gates.
kchriste said:You mean the PIC won't draw extra current when all the input pins are floating at around 1/2 Vdd? Always thought that it would. Maybe I'll experiment with this later.