bonsoir, Temps-X
J'ai testé la version ASM ...
comportement aleatoire du programme ...
un semblant de reponse de l'ADC ..puis plus rien ?
meme la commutation de mode (type de batterie ) avec le choix sur port B RB0..RB3
est aleatoire ..
je pense à un probleme de bank .. ou ???
j'ai refais un morceau de progr. en C
pour revérifier mon entrée ADC RC3
avec +VRef =4,096 et alim MCU = 5,0V
un potar de 2,2K 10 tours entre +Vcc et 0V et le curseur vers entree RC3 via mon miliamperemetre ...
vraiment currieux que
avec Vin = 105mV Ie =1.43mA
intensité qui decroit queand Vin augmente
avec Vin =4.09V ie = 0.24mA !
test Entree RC3 sous mikroC, avec +Vref=4.096
EA= ADC_Read(19) ; ne gere pas le mode avec +Vref
ex: 4.06V en entree -> seulement 3410 points
avec
EA= ADC_Get_Sample(19);
4.09V en entree -> 4095 points en sortie .. OK
Ouf !

L'entree ANA
n'est pas MORTE !peut_etre que le code ci-dessous peut tourner en version de test Mikroc si < 2Ko
en éliminant le superflu..
Code : Tout sélectionner
const code char mesg0[]=" Directory :"Directory"\r\n";
const code char mesg1[]=" MikroC pro 7.30 Beta \n\r";
const code char mesg2[] =" Projet :"Project"\r\n";
const code char mesg3[]=" Test PIC18F27K42\r\n";
const char char mesg4[]=" Config bit : "Config" FOSC:"FOSC" MHz\r\n";
const char char mesg5[]=" Eeprom: "Eeprom"\r\n";
const char char mesg6[]=" Source : "Source"_"Version".c\r\n";
const char char mesg7[]=" 18F27K42 + 1 led + UART1 19200 bds\r\n";
const char char mesg8[]=" avec LCD 1602 en mode // 4 bits \r\n";
const char char mesg9[]=" ";
const char char mesg10[]=" ";
const code char * Messages[]={mesg0,mesg1,mesg2,mesg3,mesg4,mesg5,mesg6,mesg7,mesg8,mesg9,mesg10};
const char Blancs[]=" ";
sbit LCD_RS at LATA6_bit;
sbit LCD_EN at LATA7_bit;
sbit LCD_D7 at LATA0_bit;
sbit LCD_D6 at LATA1_bit;
sbit LCD_D5 at LATA2_bit;
sbit LCD_D4 at LATA3_bit;
sbit LCD_RS_Direction at TRISA6_bit;
sbit LCD_EN_Direction at TRISA7_bit;
sbit LCD_D7_Direction at TRISA0_bit;
sbit LCD_D6_Direction at TRISA1_bit;
sbit LCD_D5_Direction at TRISA2_bit;
sbit LCD_D4_Direction at TRISA3_bit;
unsigned int i,j,k,l,m,n;
volatile unsigned char Temp=0;
volatile unsigned char Buffer1[MAX_LEN1];
volatile int Flag_Buffer1;
volatile unsigned char c1,cx;
volatile unsigned int i1;
volatile unsigned int Index1;
volatile unsigned int CptErr;
unsigned char CRam1[MAX_LEN2];
unsigned char TEXTE [MAX_LEN3];
unsigned char *txt;
volatile unsigned char TP_Deg,TP_Deci;
volatile unsigned int TAmb;
unsigned int EA0=4095;
float F1=0.00;
unsigned char * p1;
volatile unsigned int Flag_Timer0;
unsigned char Buff_LCD[33]; int Nb;
volatile unsigned int Count0 = 0;
unsigned char Etat_clock=0;
volatile struct chbits { unsigned FrameErr:1;
unsigned RAZ:1;
unsigned Elapsed:1;
unsigned Togle:1;
unsigned Second:1;
unsigned Gie:1;
unsigned Full:1;
unsigned Melodie:1;
}Drapeaux ;
void Init_Hardware();
void CRLF1(void) ;
void Raz_Buffer(void) ;
void CPrint(const char *txt);
void strConstRamCpy(unsigned char *dest, const code char *source);
void Interrupts() iv 0x0008 ics ICS_AUTO
{
if (( TMR0IE_bit) && (TMR0IF_bit))
{
TMR0H = 0x3C; TMR0L = 0xB0;
Count0++;
if (Count0 >9)
{
Flag_Timer0=1;
TMR0IE_bit=0;
}
TMR0IF_bit= 0;
}
}
void strConstRamCpy(unsigned char *dest, const code char *source)
{
while (*(source)>0) *(dest++) = *(source++) ;
*(dest) = 0 ; }
void CRLF1()
{
UART1_Write(CR); UART1_Write(LF);
}
void CPrint(const char *txt)
{
while (*(txt++)>0)
UART1_Write(*(txt));
}
void Float2Ascii (float x, unsigned char *str,char precision)
{
int ie, i, k, ndig;
double y;
ndig = ( precision<=0) ? 7 : (precision > 22 ? 23 : precision+1);
ie = 0;
if ( x < 0.0000)
{
*str++ = '-';
x = -x;
}
if (x > 0.00000) while (x < 1.00000)
{
x *= 10.000; ie--;
}
while (x >= 10.000)
{
x = x/10.000;
ie++;
}
ndig += ie; for (y = i = 1; i < ndig; i++)
y = y/10.000;
x += y/2.000;
if (x >= 10.000) {x = 1.000; ie++;}
if (ie<0)
{
*str++ = '0'; *str++ = '.';
if (ndig < 0) ie = ie-ndig;
for (i = -1; i > ie; i--) *str++ = '0';
}
for (i=0; i < ndig; i++)
{
k = x;
*str++ = k + '0';
if (i == ie ) *str++ = '.';
x -= (y=k);
x *= 10.000;
}
*str = '\0';
}
void Raz_Buffer1()
{
for(i1=0;i1<MAX_LEN1-1;i1++) Buffer1[i1]=0;
Buffer1[0]=0;
i1=0;
p1=0;
Index1=0;
Flag_Buffer1 =0 ;
c1=0;
RC1IE_bit = 1;
}
void Init_Hardware()
{
ANSELA = 0x00; ANSELB = 0x00;
ANSELC = 0x03; TRISA = 0x00;
TRISC = 0xFF;
TRISB = 0xFF;
LATA = 0x00;
}
void Init_Timer0()
{
T0CON0=0;
T0CON0.B7=1; T0CON0.B4=1; T0CON0.B3=0;
T0CON0.B2=0;
T0CON0.B1=0;
T0CON0.B0=0;
T0CON1.B7=0; T0CON1.B6=1; T0CON1.B5=0; T0CON1.ASYNC=1; T0CON1.B3=0; T0CON1.B2=1 ;
T0CON1.B1=0 ;
T0CON1.B0=1 ;
TMR0H = 0x3C; TMR0L = 0xB0;
PIR3.TMR0IF = 0;
PIE3.TMR0IE = 1 ; T0CON0.B7=1; Count0=0;
Flag_Timer0=0;
}
void LCD_Write_CText_At(char x1,char y1,const char T1)
{
if (strlen(T1<17) )
{
strConstRamCpy(Buff_LCD,T1);
Lcd_Out(x1,y1,Buff_LCD);
}
}
void main()
{
OSCTUNE=0;
OSCCON1 = 0x60;
OSCFRQ = 0x08; Etat_clock=OSCSTAT;
Etat_clock=OSCSTAT;
for (i=0;i<MAX_LEN2;i++) CRam1[i]=0;
Init_Hardware();
LCD_RS_Direction=0;
LCD_EN_Direction=0;
LCD_D7_Direction=0;
LCD_D6_Direction=0;
LCD_D5_Direction=0;
LCD_D4_Direction=0; UART1_Init(19200);
UART_Set_Active(&UART1_Read, &UART1_Write, &UART1_Data_Ready, &UART1_Tx_Idle); UART1_Write(CLS);
CPrint(" Presentation : \r\n");
for (i=0;i<10;i++) CPrint(Messages[i]);
Delay_ms(1000);
CRLF1();
txt=&TEXTE[0];
CPrint(" LCD 1602 init\r\n");
Lcd_Init();
LATA.B4=0;
LCD_Write_CText_At(1,1,"Special Chars ");
Delay_ms(100);
ADC_Init_Advanced(_ADC_INTERNAL_FVRH4 | _ADC_INTERNAL_VREFL ); CPrint(" Init ADC 4.096V for RC3 Analog input\r\n");
Init_Timer0() ;
CPrint(" Init Timer0 sur 1 sec\r\n");
Lcd_Cmd(_LCD_CLEAR); LCD_Write_CText_At(1,1,"EA0 = Pts");
IVTBASEU = 0x00; IVTBASEH = 0x00; IVTBASEL = 0x08;
GIE_bit=1;
Init_Timer0() ;
while (1)
{
LED_ROUGE = ~LED_ROUGE;
EA0=ADC_Get_Sample(19); strConstRamCpy(CRam1,"EA19= .... pts ");
WordToStr(EA0,CRam1);
k=strlen(CRam1);*(CRam1+k)=' ';
Lcd_Out(1,1,CRam1);
UART1_Write_Text(CRam1);UART1_Write(TAB);
F1=(float)EA0 /1000.0;
Float2Ascii (F1,CRam1,2);
Lcd_Out(2,1,CRam1);
UART1_Write_Text(CRam1); UART1_Write(TAB);
CRLF1();
while( Flag_Timer0==0);
Init_Timer0() ;
}
}
en points et en volts
9 .... pts 0.00
42 .... pts 0.04
485 .... pts 0.48
890 .... pts 0.89
1279 .... pts 1.28
1618 .... pts 1.62
1944 .... pts 1.94
2256 .... pts 2.26
2565 .... pts 2.56
2892 .... pts 2.89
3184 .... pts 3.18
3475 .... pts 3.48
3742 .... pts 3.74
4011 .... pts 4.01
4095 .... pts 4.09
4095 .... pts 4.09
4095 .... pts 4.09
4095 .... pts 4.09
_18F27K42_ADC_Test_on_LCD_2022.zip
Vous n’avez pas les permissions nécessaires pour voir les fichiers joints à ce message.