float r ;
float temp;
float P_R[3] = {-17,7,10};
ADCON1 = 0xFF;
TRISD = 0x00;
TRISB = 0x00;
temp = (1.4+P_R[0])/30;
r = pow( 10,temp );
r = 1/r;
a = (unsigned short) r; //a = 3
b = (unsigned short)((r-a)*10); //b = 3
PORTB = 5;
PORTD = b;
a = 3;
PORTB = a;
int a = 6;
PORTB = 5;
/* or */
PORTB = a;
the calculated value displayed as ZERO on the seven segment
Islinux, this wouldn't be on the Sourceboost compiler, would it? You haven't told us, and I can't tell by your posts.
If it is, then don't use PORTB = a; use portb =a;
That would have given an error in BoostC as PORTB isn't a legal L-value. It's like writing 5=a;
The upper/lower case stuff in boostC is a little confusing.
Mike.
void main(){
char a=1,b=2;
ADCON1 = 0xFF;
TRISB = 0x80;
TRISD = 0x00;
PORTB = a;
PORTD = b;
while(1){
if(!PORTBbits.RB7){
Delay1KTCYx(0);
TRISB = 0x00;
a = a+1;
b = b+1;
PORTB = a;
PORTD = b;
TRISB = 0x80;
}
}
}
#include <p18f4550.h>
#include <math.h>
#include <timers.h>
#include <adc.h>
#pragma config WDT = OFF
void main(){
char a,b;
float r ;
float temp;
int ReadPR;
float sampledPR;
ADCON1 = 0x0E;
TRISD = 0x00;
TRISB = 0x80;
while(1){
if(!PORTBbits.RB7){
TRISB = 0x00;
/*config A/D*/
OpenADC(ADC_FOSC_4 &
ADC_RIGHT_JUST &
ADC_2_TAD,
ADC_CH0 &
ADC_INT_OFF &
ADC_VREFPLUS_VDD,
0x0E);
/*wait for acquisition time*/
Delay1KTCYx(1);
/*start A/D conversion*/
ConvertADC();
/*wait till the conversion completed*/
while(BusyADC());
/*
conversion finished
read the converted value
*/
ReadPR = ReadADC();
sampledPR = 5*(ReadPR/1023);
temp = (1.4+sampledPR)/30;
r = pow( 10,temp );
r = 1/r;
a = (char) r;
b = (char)((r-a)*10);
PORTB =a;
PORTD =b;
TRISB = 0x80;
CloseADC();
}
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?