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 CCS Technical Support

18F4550 and LCD Analogic System

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



Joined: 18 May 2012
Posts: 3

View user's profile Send private message

18F4550 and LCD Analogic System
PostPosted: Mon Jun 04, 2012 5:58 pm     Reply with quote

Hi guys, I need your help.
When I project a analogic system, using the pic 16f877A the value which shows at LCD is like 4,54V. But when I change for 18F4550 the value which shows is like 4V 5V. This way I can´t have precision, this is a part of the program.

ADC=10bits
delay_ms(10);
set_adc_channel(0);
delay_us(10);
x=read_adc();
x=x*0.004887585532746823069403714565;


this part belongs to LCD.

#define LCD_DATA_PORT getenv("SFR:PORTd")
#define LCD_ENABLE_PIN PIN_D2
#define LCD_RS_PIN PIN_D0
#define LCD_RW_PIN PIN_D1
#define DATA0 PIN_D4
#define DATA1 PIN_D5
#define DATA2 PIN_D6
#define DATA3 PIN_D7

#include "lcd.c"


Sorry about my English.
Can anybody help me ?
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jun 04, 2012 6:03 pm     Reply with quote

1.. This line..
x=x*0.004887585532746823069403714565;
you really don't need nor will the compiler use that precision !!

2. what is 'x' declare as int8, int16, float ???

3. you should show us the whole program as well as the compiler version.
thenr.



Joined: 18 May 2012
Posts: 3

View user's profile Send private message

PostPosted: Mon Jun 04, 2012 6:24 pm     Reply with quote

The compiler is PCWHD 4.114
x,v = int16
Follow the whole program.
Code:

#include <18F4550.h>
#device adc=10 // seta precisao em 1023

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES XT                       //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES PUT                      //Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOLPT1OSC                //Timer1 configured for higher power operation
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL12                    //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV4                  //System Clock by 4
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES VREGEN                   //USB voltage regulator enabled
#FUSES ICPRT                    //ICPRT enabled

#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8

#define LCD_DATA_PORT getenv("SFR:PORTd")
#define LCD_ENABLE_PIN  PIN_D2
#define LCD_RS_PIN      PIN_D0
#define LCD_RW_PIN      PIN_D1
#define DATA0           PIN_D4
#define DATA1           PIN_D5
#define DATA2           PIN_D6
#define DATA3           PIN_D7

#include "lcd.c"

int16 x;
int16 v;

void main()
{

   setup_adc_ports(AN0_TO_AN2|VSS_VDD); //portas AN0, AN1 e AN2 como analógicas
   setup_adc(ADC_CLOCK_DIV_2);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16); //
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);   //
   setup_timer_2(T2_DIV_BY_16,62,1);         //
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(GLOBAL);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

   // TODO: USER CODE!!

LCD_init(); // chama a funcao do LCD, sem essa funcao o LCD nao
            // escreve nada

while(1){

delay_ms(10);
set_adc_channel(0);
delay_us(10);
x=read_adc();
x=x*0.004887585532746823069403714565;

delay_ms(10);
set_adc_channel(1);
delay_us(10);
v=read_adc();
v=v*0.004887585532746823069403714565;
//printf(lcd_putc,"\r\n%ld  %ld",v,x);
printf("\r\n%lu:%lu",v,x);
//printf(lcd_putc,"\nSUCESSO        X");
printf(lcd_putc,"\r\n%lu:%lu",v,x);

}
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Jun 05, 2012 3:29 am     Reply with quote

The PIC is doing what you're telling it.

When you multiply by 0.004887585532746823069403714565 you are effectively dividing by ~200.

Your maximum ADC value is 1023.

Your variables x and v are both integers so can only have the values 0,1,2,3,4 & 5.

If you want to display the range say 0.000V to 5.000V, convert your variables to mV rather than V. Then print thousands digit, decimal point, remaining digits.

Mike
thenr.



Joined: 18 May 2012
Posts: 3

View user's profile Send private message

PostPosted: Tue Jun 05, 2012 9:18 am     Reply with quote

I just changed the variables x and v for FLOAT.
Now I have the precision what I hoped.

Thank you !!
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