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.

Setting a bit from a port

Status
Not open for further replies.

SneaKSz

Member
Hello,

I'm new to C , but I had C++ @ school. I'm trying to define a PORT and then use the name to set a bit of that port.

Code:
  #define LCD_PORT	LATC
  #define LCD_RS		0x04
......

LCD_PORTbits.LCD_RS = 1; // doesn't work

LCD_PORT.LCD_RS = 1; // doesn't work


LCD_PORTbits(.LCD_RS) = 1; // doesn't work

I don't know how to set the pin LCD_RS from LCD_PORT high , in other words LATC,4

Hopefully someone can help me with this small question

Thanks !
 
You're basically going to have to learn how to program again, C++ is coded VERY differently from straight C.
What micro controller and compiler are you using?
 
Im using MPLAB with that HI-tech , my pic is 18F14K50 .

I also tried :

Code:
  #define LCD_RS		LATBbits.RB4

...
void main(void)
{ 
	LATB=0x00;
	ADCON1 = 0b01111111; // set as digital I/O 
...
}
void LCD_Cmd (unsigned char w){
	LCD_RS=0;  // I'm unable to compile this !!!!
}
I've inserted the code ( project file :C_LCD_ADC ) .

View attachment LCD_ADC.zip
 
Last edited:
Try,
Code:
volatile bit LCD_RS @ (unsigned)&LATC*8+4;

    LCD_RS=1;

Bits are numbered from location zero hence the *8 above.

Mike.
 
Hello , thanks for the suggestions , I tried the trick from Pommie , the compiler give the same compile errors again !

Look at this :
Code:
void ADC_Init()
{
		ADCON2 = 0b10101110 ;//right justify, Frc/64 , 12Tad
		ADCON1=0b00000000 ;//ADC ref = Vdd,Vss boven- en onderste venster
		TRISBbits.TRISB4=1;//Set RB4 to analog (ANS10)  , compile ERROR 
		ADCON0 = 0b00101001 ;//AN10, ADC on
}		

void ADC_Go()
{
	ADCON0bits.GO=1 ;//Start conversion , compile ERROR 
//ADCPoll:
	while(ADCON0bits.DONE==1); //Is conversion done? , compile ERROR 
	//	; Result is complete - store 2 MSbits in ADCH 
		ADCH = ADRESH;
		ADCL= ADRESL;
}

Code:
     LCD_PORT=w;
     LCD_RS=0;//RS line to 0
     TRISBbits.TRISB4=1;

Also this gives an error . I included my p18f14k50.h file and also tried htc.h , both had no succes.
I'm having a hard time to set a bit from a port with eg 'ADCON0bits.GO=1' , I'm doing the same thing like the book and still MPLab give me errors.

Someone can help me out with this small problem?

Edit : I found the correct header file and looked inside to assign the right ports. All the errors are gone except this two here :


Code:
void ADC_Go()
{
	ADCON0.GO=1 ;//Start conversion // compile error
//ADCPoll:
	while(ADCON0.DONE==1); //Is conversion done? // compile error

I cant set the second bit of ADCON0 and check the state of it .

Someone can help me out?
Thanks
 
Last edited:
Hello , thanks for the suggestions , I tried the trick from Pommie , the compiler give the same compile errors again !

It's not a trick, it's the correct way to define a bit in HiTech C. How are you now defining LCD_RS?

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top