CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC18F4550

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
vishnuk



Joined: 08 Aug 2020
Posts: 2

View user's profile Send private message

PIC18F4550
PostPosted: Sat Aug 08, 2020 10:44 pm     Reply with quote

Sir, I need to use all pins of this PIC controller. I am doing project on Proteus software.
I can read all 12 analog pins. Why? When I am connecting pin it is coming error value.

AN0
AN1
AN4
AN5
AN8
AN9
AN10
Only above pins working. Others not.
This is my program. Please help me.

Code:
#define LCD_RS_PIN PIN_D0
#define LCD_RW_PIN PIN_D1
#define LCD_ENABLE_PIN PIN_D2
#define LCD_DATA4 PIN_D3
#define LCD_DATA5 PIN_D4
#define LCD_DATA6 PIN_D5
#define LCD_DATA7 PIN_D6
 
#include <18F4550.h>
#define ANO_TO_AN11_ANALOG
#device ADC=10
#fuses NOMCLR INTRC_IO
#use delay(clock=8000000)

#include <lcd.c>

float i;

void main(){
Char str[][7]={"sAN0","sAN1","sAN2","sAN3","sAN4","sAN5","AN6","AN7","AN8","AN9","AN10","AN11"};
 int g=1;

while(1){
  setup_oscillator(OSC_8MHZ);
  lcd_init();                       
  setup_adc(ADC_CLOCK_DIV_8);
  setup_adc_ports(AN0);             
  set_adc_channel(0);               
  delay_ms(100);                   
  lcd_gotoxy(3, 2);                 
  lcd_putc("CURRENT         A");
  i = read_adc();
  i= ((2500-i)/122);
  lcd_gotoxy(11, 2);               
  printf(lcd_putc,"%f", i);     
  delay_ms(10);                 
 
  while(g<11){
    setup_adc_ports(str[g]);
    set_adc_channel(g);               
    delay_ms(1000);                   
    lcd_gotoxy(3, 1);                 
    lcd_putc("VOLTAGE:           V");
 
    i = read_adc();
    i = i*0.00489;
    lcd_gotoxy(11, 1);             
    printf(lcd_putc,"%f",i);
    delay_ms(1000);                   
    g++;
   }
  g=0;
 }

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Sun Aug 09, 2020 1:34 am     Reply with quote

First Proteus is not a way to know what a chip will really do. Read the
sticky at the top of the forum' It is badly flawed.

Then your setup_adc_ports is not going to work. The value given to this
has to be a _constant_, not a string as you are using. 'sAN0', is not a
string, it is a #defined macro, solved at compile time, not something
you can change in the code. If you want to use all the pins as analogs,
you need to set them up as analogs, and then just select the channel to
actually use.

If you want to change values as you show, you would need to declare the
array as an int32 array, not a character array, and have this contain the
values that the sANx defines contain.
However this is not going to work, since the PIC you are using does not
allow you to select just AN1 for example as an analog input. It is one
of the 'older' PIC's, that only allow you to select a range of pins for
analog, not individual pins (read the data sheet.....). So you would just
have to select all pins as analog:

AN0_TO_AN11
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group