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.
That's the brain dead part
why are you so afraid of telling us the chippie so we can help you?

this is a place for us to help each other, as you said earlier, right?
That board that's in the video is a LPC demo board the leds are on PORTC Do YOU GET that
IT's BLINKING DO YOU GET THAT the chip has just 3 PORTS PORTA PORTB PORTC
IT has ADC on PORTC
I don't need a hex I never had any broking blinky hex my blinky blinks fine
RA4 can sink only on the 16f877A DO YOU GET THAT in the data sheet maybe you missed that to.
RA4/T0CKI
pin is a Schmitt Trigger input and an open-drain output.
 
Last edited:
sorry, be80be, I didn't mean to upset you so much.

But which chip are you having trouble blinking? the sooner you tell us, the sooner we can help you.

Thanks.
 
that's the first thing I said when i read the man post why all the

is that before or after your proposed the following "fix" that didn't quite fix anything?

try this and see if it works change the xtal setting to match yours
Code:
#include <htc.h>	// Required to interface with delay routines

#ifndef _XTAL_FREQ
 // Unless already defined assume 4MHz system frequency
 // This definition is required to calibrate __delay_us() and __delay_ms()
 #define _XTAL_FREQ 4000000
#endif
void main(void){
ADCON1 =0x06 ; // Changes PORTA to digital
CMCON = 0x07 ; // Disable analog comparators
PORTA = 0x00 ;
PORTB = 0X00 ;
PORTC = 0X00 ;
PORTD = 0X00 ;
PORTE = 0X00 ;
TRISA = 0x00 ; // Configure PORTA as output
TRISB = 0X00 ;
TRISC = 0X00 ;
TRISD = 0X00 ;
TRISE = 0X00 ;

while(1){
PORTA = 0XFF ;
PORTB = 0XFF ;
PORTC = 0XFF ;
PORTD = 0XFF ;
PORTE = 0Xff ;
__delay_ms(100);
PORTA = 0X00 ;
PORTB = 0X00 ;
PORTC = 0X00 ;
PORTD = 0X00 ;
PORTE = 0X00 ;
__delay_ms(100);
}
}
 
now, going to back to the comments about incorrectly configuring the port. here is a quick run that blinks the LEDs on Port A configured as analog input.

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;		//turn off adc;
	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=0b01010101;
		delay(500);
		LED=0b10101010;
		//TODO Auto-generated main function
	}
}

as you can see, because analog pins are read as zero, LED=~LED; does not work anymore. But that's not the fault of the code, it is the fault of the programmer not reading the datasheet, not understanding the datasheet and failing to set up the port correct (analog vs digital).

this has nothing to do with multiplexing but has everything to do with incompetent programmer.
 

Attachments

  • 16f877a flashing - incorrect port configuration.PNG
    16f877a flashing - incorrect port configuration.PNG
    43.4 KB · Views: 375
Last edited:
Millwood the only reson the code I posted didn't work was he didn't set the osc right
for his chip he had ADC turn off
ADCON1=0x06; see
Code:
void main(void){
ADCON1 =0x06 ; // Changes PORTA to digital
CMCON = 0x07 ; // Disable analog comparators
PORTA = 0x00 ;
 
Millwood the only reson the code I posted didn't work was he didn't set the osc right

how could he have set the osc right?

for his chip he had ADC turn off
ADCON1=0x06; see
Code:
void main(void){
ADCON1 =0x06 ; // Changes PORTA to digital
CMCON = 0x07 ; // Disable analog comparators
PORTA = 0x00 ;

? is he NOT supposed to do that?
 
This is what you keep going on about
datasheet and failing to set up the port correct (analog vs digital).
He had the setting for it right if you look at his code you can see that he set it right
Now he didn't post what he changed for the osc but if you read he said after he change
the osc setting it worked.

here you some thing to try in you sim
Code:
main(void)
{
	unsigned char	i, j;

	TRISB = 0;		/* all bits output */
	j = 0;
	for(;;) {
		PORTB = 0x00;		/* turn all on */
		for(i = 100 ; --i ;)
			continue;
		PORTB = ~j;		/* output value of j */
		for(i = 100 ; --i ;)
			continue;
		if(BUTTON == 0)		/* if switch pressed, increment */
			j++;
	}
}
 
Last edited:
He had the setting for it right if you look at his code you can see that he set it right
Now he didn't post what he changed for the osc but if you read he said after he change
the osc setting it worked.

so are you saying he should or shouldn't turn the adc off? which position, not positins, are you taking on here?

and how does all this have anything to do with your inability to tell us on which chip you had trouble blinking the LEDs with X=~X?

just wanted to help, you know.
 
here you some thing to try in you sim
Code:
main(void)
{
	unsigned char	i, j;

	TRISB = 0;		/* all bits output */
	j = 0;
	for(;;) {
		PORTB = 0x00;		/* turn all on */
		for(i = 100 ; --i ;)
			continue;
		PORTB = ~j;		/* output value of j */
		for(i = 100 ; --i ;)
			continue;
		if(BUTTON == 0)		/* if switch pressed, increment */
			j++;
	}
}

please just let say that if I had written something like that, I would have been so embarrassed that I have to kill myself.
 
Thank you so much for your help guys ! I 've been trying for two weeks and didn't work.
I use a 18F43331 and HITECH Compiler C .

Micro571, can you please explain why you include these?

#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

I never used these header files.
All my ports blink, except some PWM ports. My configuration Bits are not set by code.
Also this command CMCON = 0x07 ; // Disable analog comparators didn't work for me, I made it a comment and managed to build it. But it works again regarding the leds.

Could you please recommend any good site with tutorials about step by step programming in HITECH C for PICs? How did you write this code? Please give me some hints !

thank you very much !
 
i want the code for configuration of oscillator of PIC 18F2455 using HI-tech C.
is this configured by using __COFIG();
the how???
can you pls send??
 
Hi, you may check if _CONFIG works for you. For example, in my case, I should write PROG_CONFIG to be able to run. Additionally, you should prefer to set the Configuration bits from the menu, and not by code. This way is easier and you minimize the chance of having mistake. To begin, try to set the first (OSCILLATOR ) to HS if you use a >=4 MHz oscilator. The last ones should be not protected. I don't remember the rest right now, I have to check my pc. Let us know if you are ok and it works or anyway.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top