Can i get any help, i am stucked,
Do not know how to read out a vaule fra AN0 ??
Do not know how to read out a vaule fra AN0 ??
Have tried to copy the posted link and no matter what i get same result while compilingThere are dozens of tutorials on the internet of how to read an analog value from a pic. All it takes is a little effort on your part to do some searching.
Here is just one:
http://www.ermicro.com/blog/?p=660
// Register: ADCON0
volatile unsigned char ADCON0 @ 0x01F;
// bit and bitfield definitions
volatile bit ADON @ ((unsigned)&ADCON0*8)+0;
volatile bit GO_nDONE @ ((unsigned)&ADCON0*8)+1;
volatile bit VCFG @ ((unsigned)&ADCON0*8)+6;
volatile bit ADFM @ ((unsigned)&ADCON0*8)+7;
volatile bit GO @ ((unsigned)&ADCON0*8)+1;
volatile bit CHS0 @ ((unsigned)&ADCON0*8)+2;
volatile bit CHS1 @ ((unsigned)&ADCON0*8)+3;
volatile bit CHS2 @ ((unsigned)&ADCON0*8)+4;
volatile bit CHS3 @ ((unsigned)&ADCON0*8)+5;
volatile bit nDONE @ ((unsigned)&ADCON0*8)+1;
volatile bit GO_DONE @ ((unsigned)&ADCON0*8)+1;
Oh that is not a problem at all. But then you must write a function that do all the hard work for you. And that is not so hard. I have feeling the datasheet is confusing you at the current momentWhy not just
X=AN0
temperture = X/something.
Yes confusing with the datasheet, and frustration to get it to compile a simpel program, just get errors when i copy a sample from the internet.Oh that is not a problem at all. But then you must write a function that do all the hard work for you. And that is not so hard. I have feeling the datasheet is confusing you at the current moment
This hobby is more than just copying something. That is fine to learn but you need to understand what is going on too.Yes confusing with the datasheet, and frustration to get it to compile a simpel program, just get errors when i copy a sample from the internet.
9.2.6 A/D CONVERSION PROCEDURE
This is an example procedure for using the ADC to
perform an Analog-to-Digital conversion:
1. Configure Port:
Disable pin output driver (See TRIS register)
Configure pin as analog
2. Configure the ADC module:
Select ADC conversion clock
Configure voltage reference
Select ADC input channel
Select result format
Turn on ADC module
3. Configure ADC interrupt (optional):
Clear ADC interrupt flag
Enable ADC interrupt
Enable peripheral interrupt
Enable global interrupt
4. Wait the required acquisition time
5. Start conversion by setting the GO/DONE bit.
6. Wait for ADC conversion to complete by one of
the following:
Polling the GO/DONE bit
Waiting for the ADC interrupt (interrupts enabled)
7. Read ADC Result
8. Clear the ADC interrupt flag (required if interrupt
is enabled).
_Yes still use the layout / board.Do you still use the low pin count demo board, with a LCD connected as I once draw it up? This board has a pot connected to RA0. Let us use this pot to simulate the temprature sensor. Let us take it from the top of this list. Just plain and simple no intterrupts
Do you still use the low pin count demo board, with a LCD connected as I once draw it up? This board has a pot connected to RA0. Let us use this pot to simulate the temprature sensor. Let us take it from the top of this list. Just plain and simple no intterrupts
TRISA = 0x03;
TRISA2=1;
ANSEL = 0b00000001; // Set PORT AN0 to analog input AN1 to AN7 digital I/O
ANSELH = 0;
ADCON0=0b10000000; // select right justify result. ADC port channel 0
ADCON1=0b01010000; // Select the FRC for 4 Mhz
ADON=1;
Rich (BB code):TRISA = 0x03; TRISA2=1; ANSEL = 0b00000001; // Set PORT AN0 to analog input AN1 to AN7 digital I/O ANSELH = 0; ADCON0=0b10000000; // select right justify result. ADC port channel 0 ADCON1=0b01010000; // Select the FRC for 4 Mhz ADON=1;
sorry, was the answers to ( or beginning of )What is your question?????
sorry, was the answers to ( or beginning of )
9.2.6 A/D CONVERSION PROCEDURE
This is an example procedure for using the ADC to
perform an Analog-to-Digital conversion:
1. Configure Port:
Disable pin output driver (See TRIS register)
Configure pin as analog
2. Configure the ADC module:
Select ADC conversion clock
Configure voltage reference
Select ADC input channel
Select result format
Turn on ADC module
3. Configure ADC interrupt (optional):
Clear ADC interrupt flag
Enable ADC interrupt
Enable peripheral interrupt
Enable global interrupt
4. Wait the required acquisition time
5. Start conversion by setting the GO/DONE bit.
6. Wait for ADC conversion to complete by one of
the following:
Polling the GO/DONE bit
Waiting for the ADC interrupt (interrupts enabled)
7. Read ADC Result
8. Clear the ADC interrupt flag (required if interrupt
is enabled).
TMR1H=0x80;
TMR1L=0;
//T1CON=0b00000110;//used during debug
T1CON=0b00001110;ADCON0=0b10000000; // select right justify result. ADC port channel 0
ADCON1=0b01010000; // Select the FRC for 4 Mhz
void vis_temp (void) // Viser temperaturen
{
unsigned int degree;
char grader[4];
ADON=1;
lcd_clear();
for(;;)
GO_DONE=1; // initiate conversion on the channel 0
while(GO_DONE) continue;
degree = ADRESL; // Get the 8 bit LSB result
degree += (ADRESH << 8); // Get the 2 bit MSB result
lcd_goto(0x00);
lcd_puts(" Ude Temp : ");
utoa(grader, degree, 10);
lcd_puts(grader);
}
If you have read from beginning, you would see that i allready have LCD to function.You need to start simple.
First just get the LCD to display something.
Write a program that prints Hello World! to the LCD.
Forget about the ADC for now.
for(;;)
GO_DONE=1; // initiate conversion on the channel 0
while(GO_DONE) continue;
degree = ADRESL; // Get the 8 bit LSB result
degree += (ADRESH << 8); // Get the 2 bit MSB result
lcd_goto(0x00);
lcd_puts(" Ude Temp : ");
utoa(grader, degree, 10);
lcd_puts(grader);
Are you sure it's not theit seems that the Go_done, / while statement is hanging up
for(;;)
Could be. Just somewhere in that statementAre you sure it's not the
that's mess things up?Rich (BB code):for(;;)