# Get starting with pic18f452

Status
Not open for further replies.

#### unicorn

##### New Member
Hello everybody
I have a problem with pic18f452 that it I do the follows to test the pic first:
first I use very simple program that outputs high all the time on the port B for example.
but when I measure the voltage on the output port it gives 0v
I have run this program with pic16f84 and more other programs on this pic with no problems.
but it is my first time to use 18f452
I think there is problem in my initialization code of the pic
I make the powerup timer = disable
watchdog = disable
brownout = disable
If it is possible to send me link of c samples codes of pic18f452

#### unicorn

##### New Member
#include<18f452.h>
#fuses HS,NOWDT,NOPROTECT,NOPUT ,NOBROWNOUT

void main()
{
while(1)
output_B(255)
}
}

Last edited:

#### blueroomelectronics

##### Well-Known Member
Which compiler is that?

#### unicorn

##### New Member
I use ccs compiler

#### be80be

##### Well-Known Member
Down load swordfish and try it You'll like is it's a lot like C and easy to get going with the 18fxxx chips you can get it here Swordfish Compiler

#### felis

##### New Member
Code:
#include<18f452.h>
#fuses HS,NOWDT,NOPROTECT,NOPUT ,NOBROWNOUT

void main()
{
while(1)
output_B(255)
}

}
There are at least two errors in this code. Have you tried to compile it?

#### unicorn

##### New Member
There are at least two errors in this code. Have you tried to compile it?
Do you mean logic error ???? so what is it?
the program is build succeeded and I compile with no objection

#### blueroomelectronics

##### Well-Known Member
Braces. Semicolons. Do you not need to setup the tris register?

#### unicorn

##### New Member
you r right it was my fault I didn't copy the original code from the compiler
I wrote it online but the program is ok and build succeeded

#### unicorn

##### New Member
Braces. Semicolons. Do you not need to setup the tris register?

about the tris register I tried this code without tris register in pic16f84 and it works very well so I thought that the command output_b(value) can setup the tris register

#### felis

##### New Member
16F84 doesn't have a TRIS register. On the other hand, PIC18 ports come configured as inputs at reset.You need to write zero to TRISx to switch PORTx pins to outputs.

#### unicorn

##### New Member
OK Thanks alot I will try it and tell u the results

#### be80be

##### Well-Known Member
That not so 16f84 has two tris register
16F84 doesn't have a TRIS .
TRISA AND TRISB I think you mean it don't take much to set up a 16f84a. The 18fxxx you have to set a lot up .
Code:
void main (void)
{
/* Make all bits on the Port B (LEDs) output bits.
* If bit is cleared, then the bit is an output bit.
*/
TRISB = 0;

while (1)
{
/* Reset the LEDs */
PORTB = 0;

/* Delay so human eye can see change */
delay ();

/* Light the LEDs */
PORTB = 0x5A;

/* Delay so human eye can see change */
delay ();
}
}

Last edited:

#### felis

##### New Member
I must have forgotten:-(. Do you remember what state they were in on reset?

#### be80be

##### Well-Known Member
This is for the 16f84a
PortA On any device reset, these pins are configured as inputs
PortB unchanged

#### rahulcet

##### New Member
On Reset is input state, mate. I thinkthe guy has to set up the Tris register

#### unicorn

##### New Member
I get tierd with this pic i don't know where is the wrong help me
this is the circuit
MyPicx.com - circuit

and this is the program

#include<18f452.h>
#fuses HS,NOWDT,NOPROTECT,NOPUT ,NOBROWNOUT
#use delay(clock=4000000)
void main()
{
set_tris_b(0);
while(1)
{
output_b(255);
delay_ms(1500);
output_b(0);
delay_ms(1500);
}
}

I use ccs compiler
the problem is there is no output and when I measure the input voltage in the circuit I get 0V
I connect the MCLR(Reset)pin to the VCC

#### be80be

##### Well-Known Member
Try this and see
Code:
#include<18f452.h>
#fuses XT,NOWDT,NOPROTECT,NOPUT ,NOBROWNOUT
#use delay(clock=400000)
void main()
{
set_tris_b(0);
while(1)
{
output_b(255);
delay_ms(1500);
output_b(0);
delay_ms(1500);
}
}
You are using a 4mhz Crystal/Resonator you set it for 40mhz
and HS is for 8 and 16 mhz

#### unicorn

##### New Member
I have tried this code and change the HS to XT,, and get the same previous results
the question is why when I put the voltage source in my circuit and measure it in the circuit it becomes 0V and when I release it from the circuit it returns again to 5V what does this mean??

Status
Not open for further replies.