unsigned short adc_val ;
void main ( )
ADCON1 = 0x00 ;
TRISA = 0xff ;
TRISB = 0x00 ;
while (1)
(
adc_val = adc_read(2) ;
portb = adc_val ;
)
)
3) For the ADC it seems pretty simple...from examples i've gotten this code, but it comes with errors. Help would be awesome.
line/column message no. message text
a) 1.3 11 ';' expected by ADCON1 found
b) 1.5 4 specifier needed
c) 1.5 12 internal error
Code:unsigned short adc_val ; void main ( ) ADCON1 = 0x00 ; TRISA = 0xff ; TRISB = 0x00 ; while (1) ( adc_val = adc_read(2) ; portb = adc_val ; ) )
// Right.
while (1)
{
// loop contents go here
}
// Wrong.
while (1)
(
// loop contents go here
)
unsigned short adc_val ;
void main ( )
{
ADCON1 = 0xFE ;
TRISA = 0x01 ;
TRISB = 0x00 ;
while (1)
{
adc_val = adc_read(0) ;
portb = adc_val ;
}
}
unsigned short in;
unsigned short inmem;
unsigned short adc_val;
void InitMain() {
PORTB = 0; // Set PORTB to 0
TRISB = 0x00; // PORTB is output
ADCON1 = 0xfe; // All ADC pin 1 to on
TRISA = 0x01; // PORTA is input
PORTC = 0; // Set PORTC to
TRISC = 0x00; // PORTC is output
Pwm_Init(5000); // Initialize PWM module
}
void main() {
InitMain();
in = adc_val; // Initial value on analog input
inmem = 0; // remembers nalog input
Pwm_Start(); // Start PWM
while (1) { // Endless loop
adc_val = adc_read(0) // read analog value on RA0
if adc_val > inmem //if analog value goes higer then last time
in++ //make duty cycle greater
if adc_val < inmem //if analog value is lower than last time
in-- // make duty cycle smaller
if (inmem != in) { // If change in duty cycle requested,
Pwm_Change_Duty(in); // set new duty ratio,
inmem = in; // memorize it,
PORTC = inmem; // and display on PORTC
}
Delay_ms(200); // Slow down a bit
}
while (1)
{
adc_val = adc_read(0) ; //read analog input Ra0
portb = adc_val ; //output 8bt on port B
}
}
}
while (1) { // Endless loop
adc_val = adc_read(0) // read analog value on RA0
if adc_val > inmem //if analog value goes higer then last time
in++ //make duty cycle greater
if adc_val < inmem //if analog value is lower than last time
in-- // make duty cycle smaller
if (inmem != in) { // If change in duty cycle requested,
Pwm_Change_Duty(in); // set new duty ratio,
inmem = in; // memorize it,
PORTC = inmem; // and display on PORTC
}
Delay_ms(200); // Slow down a bit
}
while (1)
{
adc_val = adc_read(0);
if (adc_val > duty_cycle)
Pwm_Change_Duty(++duty_cycle);
else if (adc_val < duty_cycle)
Pwm_Change_Duty(--duty_cycle);
PORTC = duty_cycle;
Delay_ms(200);
}
while (1)
{
adc_val = adc_read(0); //read analog input RA0
if (adc_val > duty_cycle) // if value is higher
Pwm_Change_Duty(++duty_cycle); //then increase duty
else if (adc_val < duty_cycle) //if value is lower
Pwm_Change_Duty(--duty_cycle); //lower duty
PORTC = duty_cycle; //output PWM on C
Delay_ms(200); //slow down process
}
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?