Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Hi-Tech C Compiler: What am I doing wrong?

Status
Not open for further replies.
Are you all right
1. I didn't start this thread
2. I didn't write the code that was posted
3. All I did was try the poster code
4. And your code
5. I posted why it didn't run.
6 I said this on page 2 PORT configuration are wrong
And now we have a baby show of who is right and wrong I don't no about you
but I was trying to help the poster

no reason to jump up and down declaring your intent: we don't question the least bit of your intent to help the others. and you shouldn't either.

and in my very first post on this very thread, I said that "I assume the port configurations are right" - I simply didn't have time to check it out, and I took that as rudimentary for anyone with any experience programming any mcu.

if you had tried his code and then realized that the port settings are wrong, ...
 
this whole thing really gets me intrigued about this chip.

here is the block diagram and it shows adc on PORTA, and pwm/spi/i2c/uart on PORTC.

if ever we ever had the problem with incorrectly configuring an "analog" port and not being able to set it low, shouldn't that problem show up on PORTA instead?

what am I missing?

now, I would really love to see how be80be did it on PORTC but managed to get PORTA to defy the datasheet.
 

Attachments

  • 16f877 blocks.PNG
    16f877 blocks.PNG
    55.4 KB · Views: 309
no reason to jump up and down declaring your intent: we don't question the least bit of your intent to help the others. and you shouldn't either.

However, you have bloated a thread with irrelevant arguments because you didn't read the data sheet or, if you did read it, you didn't understand it. If you do now understand it then your arrogance has stopped you admitting it.

I hope that in future I am able to differentiate between newbies that want to learn and those that want to waste everyones time.

Mike.
 
However, you have bloated a thread with irrelevant arguments because you didn't read the data sheet or, if you did read it, you didn't understand it. If you do now understand it then your arrogance has stopped you admitting it.

I hope that in future I am able to differentiate between newbies that want to learn and those that want to waste everyones time.

Mike.

you are mad because you didn't understand what was going wrong with the program.

the reason PORTC isn't working is that upon power-on, TRISC is set to 0xff. That means all PORTC pins are in DIGITAL INPUT.

it has nothing to do with being "analog mode" - that could have been the right argument for PORTA which does have the adc on.

all of that are in the datasheet, which you clearly haven't read, or couldn't comprehend.
 
Let's get this strait the poster has a 16f877a I did read the data sheet. I tried his code on
the chip i was using but my chip has adc on portC so I fixed the code so it would run On my chip. 3v0 posted about lata 16f don't have a latch. Now I no the code will run it has to be like Mike said and it was number 5 on his list
 
Last edited:
I was so curious that I tried this on my own computer.

16f877, picc-lite, hi-tide ide.

Code:
#include <htc.h>

//hardware configuration
#define LEDC	PORTC
//end hardware configuration

//configuration bits

__CONFIG( XT & WDTDIS & PWRTDIS & BORDIS & LVPDIS & WRTEN & DEBUGDIS & UNPROTECT );


void init_mcu(void);
void delay(int dly);

void init_mcu(void) {
	
//up on power-on, porta set to analog input.
	
	TRISC=0b00000000;	//set all pins on port C as output.
	
}

void delay(int dly) {
	for(;dly>0; dly--)
		;
}


void
main(void)
{

	init_mcu();
	LEDC=0b10101010;
	while (1){
		delay(500);
		LEDC=~LEDC;
		//TODO Auto-generated main function
	}
}

here is what it shows in simulation. as you can see, the LEDs did blink, and the logic analyzer agrees too, :).
 

Attachments

  • 16f877 blinky.PNG
    16f877 blinky.PNG
    42.9 KB · Views: 248
Let's get this strait the poster has a 16f877a I did read the data sheet.

bingo!

the big give-away is how he set the adcon/cmcon registers for port a.

But either way, that has no impact on port C, which is where you guys thought his problem was.
 
here is the same code running on port C of 16f877A.

those blinkies are really nice, :)
 

Attachments

  • 16F877A blinky.PNG
    16F877A blinky.PNG
    40.3 KB · Views: 263
Last edited:
Millwood you can program Ok but You haven't even read what the poster has posted he didn't have any leds on portc when he first posted it looks like he was going to use all 32 I/O but here is where he said how he set up the chip.
I've only got 2.

One connected to RA0 and one connected to RD1.

Using the example hex I linked to, the LED at RA0 blinks.
 
Millwood you can program Ok but You haven't even read what the poster has posted he didn't have any leds on portc when he first posted it looks like he was going to use all 32 I/O but here is where he said how he set up the chip.

I thought you guys said that X=~X would work on ANY port, and you specifically said it didn't work for you on port C (of a different chip, you later clarified).

I am happy to run it on port C of your chip if you care to tell me what chip you failed to blink the leds on.
 
Yep, I only had 2 LEDs.

I was toggling all PORTs so that I could see something happen even if I put the led in the wrong spot.

This code works for me for toggling:
<code>
while(1){
DelayMs(500);
PORTA = ~PORTA;
PORTB = ~PORTB;
PORTC = ~PORTC;
PORTD = ~PORTD;
PORTE = ~PORTE;
}
</code>
 
you want to blink port D?

you get your freaking blinking port D, :).

I didn't want to change it too much but you can see that some bits of port D is on and others off.
 

Attachments

  • 16F877A blinky port D.PNG
    16F877A blinky port D.PNG
    40.7 KB · Views: 197
how about blinky some port A? :)

Code:
#include <htc.h>

//hardware configuration
#define LED		PORTA
//end hardware configuration

//configuration bits

__CONFIG( XT & WDTDIS & PWRTDIS & BORDIS & LVPDIS & WRTEN & DEBUGDIS & UNPROTECT );


void init_mcu(void);
void delay(int dly);

void init_mcu(void) {
	
//up on power-on, porta set to analog input.
	
	ADCON1=0x06;
	TRISA=0b00000000;	//set all pins on port C as output.
	
}

void delay(int dly) {
	for(;dly>0; dly--)
		;
}


void
main(void)
{

	init_mcu();
	LED=0b10101010;
	while (1){
		delay(500);
		LED=~LED;
		//TODO Auto-generated main function
	}
}

and simulation with updated traces on the logic analyzer.
 

Attachments

  • 16F877A blinky port A.PNG
    16F877A blinky port A.PNG
    45.8 KB · Views: 212
Millwood you can program Ok but You haven't even read what the poster has posted he didn't have any leds on portc when he first posted it looks like he was going to use all 32 I/O but here is where he said how he set up the chip.

My offer to you continues: as long as you tell me which chip's port C you have trouble blinking, I am happy to write a piece of code to blink it to you, and send you the .hex file.

all for free, :)

how's that for our friendship.

that offer applies to prommie too.
 
Yep, I only had 2 LEDs.

I was toggling all PORTs so that I could see something happen even if I put the led in the wrong spot.

This code works for me for toggling:
Code:
	while(1){
		DelayMs(500);
		PORTA = ~PORTA;
		PORTB = ~PORTB;
		PORTC = ~PORTC;
		PORTD = ~PORTD;
		PORTE = ~PORTE;
		}

I believe you problem lies somewhere else, not in this piece of code.

have you tried to trace it in hi-tide to see if the ports actually change values?
 
Last edited:
Are you brain dead or what it was setup not the code and do you think your the first to
Code:
portc =~portc
that's the first thing I said when i read the man post why all the
Code:
while(1){
PORTA = 0XFF ;
PORTB = 0XFF ;
PORTC = 0XFF ;
PORTD = 0XFF ;
PORTE = 0Xff ;
DelayMs(500);
PORTA = 0X00 ;
PORTB = 0X00 ;
PORTC = 0X00 ;
PORTD = 0X00 ;
PORTE = 0X00 ;
DelayMs(500);
}
}

I don't need a hex and I posted the code for this
Code:
void main (){
ANSEL = 0;                  // makes PORTC digital 
PORTC = 0;                 // Initialize PORTC
TRISC = 0;                 // Configure PORTC as output
while(1){
  Delay_Ms(100);
  PORTC = ~PORTC;
 }
}
here you can watch it blink
[embed]http://www.youtube.com/v/SCpjRvNJtVQ&hl=en&fs=1&[/embed]
maybe you can figure what chip has adc on PORTC from the video have fun
Oh I forgot some thing
Pin RA4 is multiplexed with the Timer0 module clock
input to become the RA4/T0CKI pin. The RA4/T0CKI
pin is a Schmitt Trigger input and an open-drain output.
All other PORTA pins have TTL input levels and full
CMOS output drivers.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top