R
Rajeshwariembedded
Guest
Som nový radič pre PIC.
Já jsem na testovanie vstavaný ADC v 16f877a.
Snažil som sa vo volebných metódou s pomocou 10Kpot.
Umím čítaj hodnotu, ale čítať ako 0V až 2.5V a 2.5V opäť na 0V.
Som uplatňovanie napätie na hrniec je 5V.
Ale to nie je dosiahnutie maximálnej hodnoty.
Aký môže byť problém.
Budem sa prikladajú kódovanie, môže ktokoľvek, pomôžte mi prosím
Pridané po 4 minútach:
Prepáčte, zabudol som pripojiť kódovanie.
Tu kódovanie vyplýva, as/ / LCD Konfigurace
/ / RS RC6/ / E RC7
#
Include <16f877a.h>#
Include <string.h>#
Include <stdlib.h>
# Zápalníc HS, NOWDT, NOLVP, NOPROTECT, NOBROWNOUT, nodebug
# Použitie meškanie (hodiny = 20000000)# Bajtov TRIS = 0x85# Byte TRISB = 0x86# Byte smietke = 0x87# Byte TRISD = 0x88# Byte TRIS = 0x89
# Bajtov PORTA = 0x05# Bajtov PORTB = 0x06# Byte PORTC = 0x07# Byte PORTD = 0x08# Bajtov PORTE = 0x09
# Byte ADRESH = 0x1e# Byte ADRESL = 0x9e# Byte ADCON0 = 0x1F# Byte ADCON1 = 0x9f
# Bit godono = ADCON0.2# Bit Adony = ADCON0.0
# Bit HBLED = PORTB.5# Bit HBLEDD = TRISB.5
# Bit LCDRS = PORTC.6# Bit LCDRSD = TRISC.6
# Bit ENB = PORTC.7# Bit ENBD = TRISC.7
#
Define Dataline PORTD
unsigned int ledcount = 0;
unsigned char j = 0;
Únie Pulzná(unsigned long intnum;unsigned char charnum [2]Pulsecount;# INT_TIMER0void Timer0_isr ()(if ( ledcount> 5)(ledcount = 0;HBLED = ~ HBLED)void meškanie (unsigned char sec)(unsigned char i, k;
for (k = 0; k <sec, k )(for (i = 0; i <200; i ))void delay1 (unsigned int del)(unsigned int i, k;
for (k = 0; k <del, k )(for (i = 0; i <200; i ))void Commandreg (unsigned char Command)(LCDRS = 0;Dataline = príkaz;ENB = 1;omeškania (20);ENB = 0
void Datareg (unsigned char Datadis)(LCDRS = 1;Dataline = Datadis;ENB = 1;omeškania (20);ENB = 0
void Lcdinitialize (void)(
Commandreg (0x01); / / Cleardisplayomeškania (20);
Commandreg (0x0c); / / Zobraz / vypnutie ovládanieomeškania (20);
Commandreg (0x3a); / / Funkcia nastavíomeškania (20);
Commandreg (0x06); / / Entrymode setomeškania (20);
)
void Clearline1 (void)(Commandreg (0x02) / / Návrat domovomeškania (20);
u (j = 0; j <16; j )(Datareg ('');omeškania (20)
Commandreg (0x02) / / Návrat domovomeškania (20)
void Clearline2 (void)(
Commandreg (0xC0); / / Návrat domovomeškania (20);
u (j = 0; j <16; j )(Datareg ('');omeškania (20)
Commandreg (0xC0); / / Návrat domovomeškania (20)
void rightcursorpos (unsigned char POS)(unsigned char j;u (j = 0; j <pos; j )(Commandreg (0x14) / / Návrat domovomeškania (20))void go (unsigned char a, unsigned char b)(if (a == 1)Commandreg (0x02) / / Návrat domovelse if (a == 2)Commandreg (0xC0); / / Návrat domovomeškania (10);rightcursorpos (b);
)
void Displayfun (unsigned char * str)(unsigned char dĺžka = 0, check = 0;check = strlen (str);pre (dĺžka = 0; dĺžka <skontrolujte, dĺžka )(Datareg (str [dĺžka]);omeškania (20))void main ()(
unsigned char String [8] = "Vitajte";unsigned char ADCVal [7] = "0.00V";int Hex1;
float c;int ref;char MSBValue = 0, LSBValue = 0, Printvalue1, Printvalue2, count = 0;
/ / Setup_adc_ports (NO_ANALOGS);/ / Setup_adc (ADC_OFF);setup_psp (PSP_DISABLED);setup_spi (FALSE);setup_timer_0 (RTCC_INTERNAL | RTCC_DIV_256);setup_timer_1 (T1_DISABLED);setup_timer_2 (T2_DISABLED, 0,1);setup_comparator (NC_NC_NC_NC);setup_vref (FALSE);
enable_interrupts (globálne);enable_interrupts (INT_TIMER0);/ / Enable_interrupts (INT_AD);set_timer0 (0);
HBLEDD = 0; / / Srdce Beat Direction LED bit
TRISD = 0x00, / / Réžia linky
LCDRSD = 0; / / LCD - RS Réžia bit
ENBD = 0; / / LCD - Umožniť Réžia bit
Dataline = 0x00;
Lcdinitialize ();omeškania (15);
Datareg ( 'R');
Clearline1 ();Clearline2 ();
Choď (1,0);Displayfun (String);
Choď (2,0);
Displayfun (ADCVal);
omeškania (100);
omeškania (100);
/ / ADCON0 = 0xc1;/ / ADCON1 = 0x0e;
TRIS = 0xff;TRIS = 0xff;
Clearline1 ();Clearline2 ();Godono = 1;while (1)(
Adony = 1;
if (godono == 0)(Pulsecount.charnum [1] = ADRESH;Pulsecount.charnum [0] = ADRESL;
/************************************************* ** /
Pulsecount.intnum = Pulsecount.intnum>> 6;
/ / C = ((((Pulsecount.intnum) * 5) / 1024) * 100);
c = (Pulsecount.intnum * 0,4882);/ / C = (Pulsecount.intnum * 1,9531);
Hex1 = (int) c;
Choď (1,10);
Datareg ((Hex1/100) 0x30);
Datareg (((Hex1% 100) / 10) 0x30);
Datareg (((Hex1% 100)% 10) 0x30);
/************************************************* ** /
Godono = 1;
delay1 (5000);delay1 (5000);Clearline1 ();Clearline2 ();delay1 (5000)
)
)
Já jsem na testovanie vstavaný ADC v 16f877a.
Snažil som sa vo volebných metódou s pomocou 10Kpot.
Umím čítaj hodnotu, ale čítať ako 0V až 2.5V a 2.5V opäť na 0V.
Som uplatňovanie napätie na hrniec je 5V.
Ale to nie je dosiahnutie maximálnej hodnoty.
Aký môže byť problém.
Budem sa prikladajú kódovanie, môže ktokoľvek, pomôžte mi prosím
Pridané po 4 minútach:
Prepáčte, zabudol som pripojiť kódovanie.
Tu kódovanie vyplýva, as/ / LCD Konfigurace
/ / RS RC6/ / E RC7
#
Include <16f877a.h>#
Include <string.h>#
Include <stdlib.h>
# Zápalníc HS, NOWDT, NOLVP, NOPROTECT, NOBROWNOUT, nodebug
# Použitie meškanie (hodiny = 20000000)# Bajtov TRIS = 0x85# Byte TRISB = 0x86# Byte smietke = 0x87# Byte TRISD = 0x88# Byte TRIS = 0x89
# Bajtov PORTA = 0x05# Bajtov PORTB = 0x06# Byte PORTC = 0x07# Byte PORTD = 0x08# Bajtov PORTE = 0x09
# Byte ADRESH = 0x1e# Byte ADRESL = 0x9e# Byte ADCON0 = 0x1F# Byte ADCON1 = 0x9f
# Bit godono = ADCON0.2# Bit Adony = ADCON0.0
# Bit HBLED = PORTB.5# Bit HBLEDD = TRISB.5
# Bit LCDRS = PORTC.6# Bit LCDRSD = TRISC.6
# Bit ENB = PORTC.7# Bit ENBD = TRISC.7
#
Define Dataline PORTD
unsigned int ledcount = 0;
unsigned char j = 0;
Únie Pulzná(unsigned long intnum;unsigned char charnum [2]Pulsecount;# INT_TIMER0void Timer0_isr ()(if ( ledcount> 5)(ledcount = 0;HBLED = ~ HBLED)void meškanie (unsigned char sec)(unsigned char i, k;
for (k = 0; k <sec, k )(for (i = 0; i <200; i ))void delay1 (unsigned int del)(unsigned int i, k;
for (k = 0; k <del, k )(for (i = 0; i <200; i ))void Commandreg (unsigned char Command)(LCDRS = 0;Dataline = príkaz;ENB = 1;omeškania (20);ENB = 0
void Datareg (unsigned char Datadis)(LCDRS = 1;Dataline = Datadis;ENB = 1;omeškania (20);ENB = 0
void Lcdinitialize (void)(
Commandreg (0x01); / / Cleardisplayomeškania (20);
Commandreg (0x0c); / / Zobraz / vypnutie ovládanieomeškania (20);
Commandreg (0x3a); / / Funkcia nastavíomeškania (20);
Commandreg (0x06); / / Entrymode setomeškania (20);
)
void Clearline1 (void)(Commandreg (0x02) / / Návrat domovomeškania (20);
u (j = 0; j <16; j )(Datareg ('');omeškania (20)
Commandreg (0x02) / / Návrat domovomeškania (20)
void Clearline2 (void)(
Commandreg (0xC0); / / Návrat domovomeškania (20);
u (j = 0; j <16; j )(Datareg ('');omeškania (20)
Commandreg (0xC0); / / Návrat domovomeškania (20)
void rightcursorpos (unsigned char POS)(unsigned char j;u (j = 0; j <pos; j )(Commandreg (0x14) / / Návrat domovomeškania (20))void go (unsigned char a, unsigned char b)(if (a == 1)Commandreg (0x02) / / Návrat domovelse if (a == 2)Commandreg (0xC0); / / Návrat domovomeškania (10);rightcursorpos (b);
)
void Displayfun (unsigned char * str)(unsigned char dĺžka = 0, check = 0;check = strlen (str);pre (dĺžka = 0; dĺžka <skontrolujte, dĺžka )(Datareg (str [dĺžka]);omeškania (20))void main ()(
unsigned char String [8] = "Vitajte";unsigned char ADCVal [7] = "0.00V";int Hex1;
float c;int ref;char MSBValue = 0, LSBValue = 0, Printvalue1, Printvalue2, count = 0;
/ / Setup_adc_ports (NO_ANALOGS);/ / Setup_adc (ADC_OFF);setup_psp (PSP_DISABLED);setup_spi (FALSE);setup_timer_0 (RTCC_INTERNAL | RTCC_DIV_256);setup_timer_1 (T1_DISABLED);setup_timer_2 (T2_DISABLED, 0,1);setup_comparator (NC_NC_NC_NC);setup_vref (FALSE);
enable_interrupts (globálne);enable_interrupts (INT_TIMER0);/ / Enable_interrupts (INT_AD);set_timer0 (0);
HBLEDD = 0; / / Srdce Beat Direction LED bit
TRISD = 0x00, / / Réžia linky
LCDRSD = 0; / / LCD - RS Réžia bit
ENBD = 0; / / LCD - Umožniť Réžia bit
Dataline = 0x00;
Lcdinitialize ();omeškania (15);
Datareg ( 'R');
Clearline1 ();Clearline2 ();
Choď (1,0);Displayfun (String);
Choď (2,0);
Displayfun (ADCVal);
omeškania (100);
omeškania (100);
/ / ADCON0 = 0xc1;/ / ADCON1 = 0x0e;
TRIS = 0xff;TRIS = 0xff;
Clearline1 ();Clearline2 ();Godono = 1;while (1)(
Adony = 1;
if (godono == 0)(Pulsecount.charnum [1] = ADRESH;Pulsecount.charnum [0] = ADRESL;
/************************************************* ** /
Pulsecount.intnum = Pulsecount.intnum>> 6;
/ / C = ((((Pulsecount.intnum) * 5) / 1024) * 100);
c = (Pulsecount.intnum * 0,4882);/ / C = (Pulsecount.intnum * 1,9531);
Hex1 = (int) c;
Choď (1,10);
Datareg ((Hex1/100) 0x30);
Datareg (((Hex1% 100) / 10) 0x30);
Datareg (((Hex1% 100)% 10) 0x30);
/************************************************* ** /
Godono = 1;
delay1 (5000);delay1 (5000);Clearline1 ();Clearline2 ();delay1 (5000)
)
)