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.

[HELP] PIC18F4550 -- C Programming Problems

Status
Not open for further replies.

scdvom

Member level 1
Joined
Feb 8, 2010
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,524
Hi, I got a problems here. Here is my code

Code:
#include <P18F4550.h>

void main (void)
{
TRISB = 0;	//Make port B as output
PORTB = 0xFF;
}

when I check d Logic Analyzer (waveform), how come it just trigered wif pin 5,6, and 7 only. then hw pin 1,2,3,4?? i tot 0xFF is all turning on??

can any help me to solve tis problem. thx
 

Are all the pins configured to be digital outputs? Most have more than one use and you may for example, have them configured as analog inputs.

Brian.
 

erm..no...hw can I configure all to be digital outputs??
thx 4 helping
 

Hi scdvom,
RB0...4 are configured as analog pins. To configure them as digital, add this to your code:
Code:
   ADCON1 = 7; //Turn off ADC module

Hope this helps.
Tahmid.
 

hi, Tahmid. thx 4 ur helping again.its work.thx..^^
erm..I got another question here..like I wan to convert decimal form to hex form.can do I make it?

int x
x=3 //actually = 11
y=x //bt y i wish to show "11"...so wat should declare on y??

char y ???

Added after 9 minutes:

sorry..is decimal to binary..
 

Where do you want to display binary?
At PORTB, binary is displayed.
If you mean write binary, I think you write it like this:
Code:
int x; //Or char x
x = 0b11;
y = x;

Hope this helps.
Tahmid.
 

here is my code...

Code:
void masterStateMachine(void)
{
	unsigned char fbBits, lrBits, masterBits;

	fbBits = fb.controlBits;				//(fb fb)
	lrBits = lr.controlBits;					//(lr lr)
	masterBits = (fbBits<<2)+(lrBits);		//(fb fb)(lr lr)
 	
	/*
	00:Rest
	01:Forward/Left
	10:Reverse/Right
	*/
	
	switch(masterBits)
	{
		case 0: stop(); break;
		case 1: turnLeft(); break;
.
.
.
.

fb.controlBits and lr.controlBits both are either 0,1, or 3..bt when I wanna store inside fbBits nad lrBits...i need to be binary form.

thx 4 helping
 

As far as an unsigned char is concerned, it can only store a binary number????

decimal 3 is stored as 00000011

hex 0x03 is stored as 00000011

It's a matter of interpretation.

PS
Your code doesn't look like a State machine implementation. Looks more like a loop?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top