aetius Postat August 9, 2014 Partajează Postat August 9, 2014 /*Monitorizare Incarcare Baterie Solara -Afisare stare baterie, la % incarcat *Configuratie: -PIC16F876A -Cristal 4 Mhz -LCD alfanumeric 16X2 *Autor aetius */ //Conexiuni LCD sbit LCD_RS at RB1_bit; sbit LCD_EN at RB3_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB1_bit; sbit LCD_EN_Direction at TRISB3_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; unsigned int adc_rd, diff; unsigned long int BarSegmentNum; char adcprint, i, ip; const char character1[] = {0,0,0,0,0,0,31,0}; const char character2[] = {0,0,0,0,0,31,31,0}; const char character3[] = {0,0,0,0,31,31,31,0}; const char character4[] = {0,0,0,31,31,31,31,0}; const char character5[] = {0,0,31,31,31,31,31,0}; const char character6[] = {0,31,31,31,31,31,31,0}; const char character7[] = {31,31,31,31,31,31,31,0}; void main() { INTCON = 1; // Dezactivare intreruperi TRISA = 0x03; // RA0, setate ca intrare Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear LCD Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off //1 segment symbol Lcd_Cmd(64); for (ip=0;ip<=7;ip++) Lcd_Chr_Cp(character1[ip]); //2 segment symbol Lcd_Cmd(72); for (ip=0;ip<=7;ip++) Lcd_Chr_Cp(character2[ip]); //3 segment symbol Lcd_Cmd(80); for (ip=0;ip<=7;ip++) Lcd_Chr_Cp(character3[ip]); //4 segment symbol Lcd_Cmd(88); for (ip=0;ip<=7;ip++) Lcd_Chr_Cp(character4[ip]); //5 segment symbol Lcd_Cmd(96); for (ip=0;ip<=7;ip++) Lcd_Chr_Cp(character5[ip]); //6 segment symbol Lcd_Cmd(104); for (ip=0;ip<=7;ip++) Lcd_Chr_Cp(character6[ip]); //7 segment symbol Lcd_Cmd(112); for (ip=0;ip<=7;ip++) Lcd_Chr_Cp(character7[ip]); ADC_Init(); while(1) { adc_rd = ADC_Get_Sample(0); // Get ADC value from 1st channel if (diff != adc_rd) { Lcd_out(1,1," "); Lcd_out(2,1," "); Lcd_out(2,8,"BATTERY"); if (adc_rd <82) { Lcd_out(1,1,"10%"); Lcd_out(1,7,"LOW"); Lcd_Chr(2,1,0); } if ((adc_rd >82) && (adc_rd <164)) { Lcd_out(1,1,"20%"); Lcd_out(1,7,"LOW"); Lcd_Chr(2,1,0); Lcd_Chr(2,2,1); } if ((adc_rd > 164) && (adc_rd < 246)) { Lcd_out(1,1,"30%"); Lcd_out(1,7,"CHARGING"); Lcd_Chr(2,1,0); Lcd_Chr(2,2,1); } if ((adc_rd > 246) && (adc_rd < 328)) { Lcd_out(1,1,"40%"); Lcd_out(1,7,"CHARGING"); Lcd_Chr(2,1,0); Lcd_Chr(2,2,1); Lcd_Chr(2,3,2); } if ((adc_rd > 328) && (adc_rd < 410)) { Lcd_out(1,1,"50%"); Lcd_out(1,7,"CHARGING"); Lcd_Chr(2,1,0); Lcd_Chr(2,2,1); Lcd_Chr(2,3,2); } if ((adc_rd > 410) && (adc_rd < 492)) { Lcd_out(1,1,"60%"); Lcd_out(1,7,"CHARGING"); Lcd_Chr(2,1,0); Lcd_Chr(2,2,1); Lcd_Chr(2,3,2); Lcd_Chr(2,4,3); } if ((adc_rd > 492) && (adc_rd < 574)) { Lcd_out(1,1,"70%"); Lcd_out(1,7,"CHARGING"); Lcd_Chr(2,1,0); Lcd_Chr(2,2,1); Lcd_Chr(2,3,2); Lcd_Chr(2,4,3); } if ((adc_rd > 574) && (adc_rd < 656)) { Lcd_out(1,1,"80%"); Lcd_out(1,7,"CHARGING"); Lcd_Chr(2,1,0); Lcd_Chr(2,2,1); Lcd_Chr(2,3,2); Lcd_Chr(2,4,3); Lcd_Chr(2,5,4); } if ((adc_rd > 656) && (adc_rd < 738)) { Lcd_out(1,1,"90%"); Lcd_out(1,7,"CHARGING"); Lcd_Chr(2,1,0); Lcd_Chr(2,2,1); Lcd_Chr(2,3,2); Lcd_Chr(2,4,3); Lcd_Chr(2,5,4); Lcd_Chr(2,6,5); } if ((adc_rd > 738) && (adc_rd < 778)) { Lcd_out(1,1,"100%"); Lcd_out(1,7,"CHARGED"); Lcd_Chr(2,1,0); Lcd_Chr(2,2,1); Lcd_Chr(2,3,2); Lcd_Chr(2,4,3); Lcd_Chr(2,5,4); Lcd_Chr(2,6,5); Lcd_Chr(2,7,6); } if (adc_rd > 778) { Lcd_out(1,7,"CHARGED"); Lcd_Chr(2,1,0); Lcd_Chr(2,2,1); Lcd_Chr(2,3,2); Lcd_Chr(2,4,3); Lcd_Chr(2,5,4); Lcd_Chr(2,6,5); Lcd_Chr(2,7,6); } } Delay_ms(1000); // Stabilize LCD display diff = adc_rd; } } Problema este urmatoarea ...imi afiseaza 70 % CHARGING ,80% ,90 % CHRAGING, nu imi afiseaza si la 80% CHARGING... Scuze dar nu pot incarca simularea in proteus. Multumesc. Link spre comentariu
Liviu M Postat August 9, 2014 Partajează Postat August 9, 2014 Chiar la partea cu probleme eu nu vad nimic aiurea, da' esti sigur ca ai scris bine partea cu afisat de caractere?Adica m-as fi asteptat ca in loc de Lcd_Chr(2,1,0); sa ai Lcd_Chr(2,1,'0'); Link spre comentariu
aetius Postat August 9, 2014 Autor Partajează Postat August 9, 2014 (editat) // LCD pins definitionsbit LCD_RS at LATB4_bit;sbit LCD_EN at LATB5_bit;sbit LCD_D4 at LATB0_bit;sbit LCD_D5 at LATB1_bit;sbit LCD_D6 at LATB2_bit;sbit LCD_D7 at LATB3_bit;sbit LCD_RS_Direction at TRISB4_bit;sbit LCD_EN_Direction at TRISB5_bit;sbit LCD_D4_Direction at TRISB0_bit;sbit LCD_D5_Direction at TRISB1_bit;sbit LCD_D6_Direction at TRISB2_bit;sbit LCD_D7_Direction at TRISB3_bit;unsigned int adc_rd, diff;unsigned long int BarSegmentNum;char adcprint, i, ip;const char character1[] = {16,16,16,16,16,16,16,16};const char character2[] = {24,24,24,24,24,24,24,24};const char character3[] = {28,28,28,28,28,28,28,28};const char character4[] = {30,30,30,30,30,30,30,30};const char character5[] = {31,31,31,31,31,31,31,31};void main(){ ANSELA.F0 = 1; // Configure RA0 pin as analog TRISA.F0 = 1; // Configure RA0 pin as input Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear LCD Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off//1 segment symbol Lcd_Cmd(64); for (ip=0;ip<=7;ip++) Lcd_Chr_Cp(character1[ip]);//2 segment symbol Lcd_Cmd(72); for (ip=0;ip<=7;ip++) Lcd_Chr_Cp(character2[ip]);//3 segment symbol Lcd_Cmd(80); for (ip=0;ip<=7;ip++) Lcd_Chr_Cp(character3[ip]);//4 segment symbol Lcd_Cmd(88); for (ip=0;ip<=7;ip++) Lcd_Chr_Cp(character4[ip]);//5 segment symbol Lcd_Cmd(96); for (ip=0;ip<=7;ip++) Lcd_Chr_Cp(character5[ip]); ADC_Init(); while(1) { adc_rd = ADC_Get_Sample(0); // Get ADC value from 1st channel if (diff != adc_rd) { Lcd_out(1,1," "); Lcd_out(2,1," "); if (adc_rd < 205) { Lcd_out(1,1,"1"); Lcd_Chr(2,1, 0); } if ((adc_rd > 205) && (adc_rd < 410)) { Lcd_out(1,1,"1"); Lcd_Chr(2,1, 0); Lcd_out(1,2,"2"); Lcd_Chr(2,2, 1); } if ((adc_rd > 410) && (adc_rd < 615)) { Lcd_out(1,1,"1"); Lcd_Chr(2,1, 0); Lcd_out(1,2,"2"); Lcd_Chr(2,2, 1); Lcd_out(1,3,"3"); Lcd_Chr(2,3, 2); } if ((adc_rd > 615) && (adc_rd < 820)) { Lcd_out(1,1,"1"); Lcd_Chr(2,1, 0); Lcd_out(1,2,"2"); Lcd_Chr(2,2, 1); Lcd_out(1,3,"3"); Lcd_Chr(2,3, 2); Lcd_out(1,4,"4"); Lcd_Chr(2,4, 3); } if (adc_rd > 820) { Lcd_out(1,1,"1"); Lcd_Chr(2,1, 0); Lcd_out(1,2,"2"); Lcd_Chr(2,2, 1); Lcd_out(1,3,"3"); Lcd_Chr(2,3, 2); Lcd_out(1,4,"4"); Lcd_Chr(2,4, 3); Lcd_out(1,5,"5"); Lcd_Chr(2,5, 4); } } Delay_ms(1000); // Stabilize LCD display diff = adc_rd; }} codul dupa care m-am inspirit,numai ca in loc de cifrele 12345, afiseaza altceva ales de mine Editat August 9, 2014 de aetius Link spre comentariu
Liviu M Postat August 9, 2014 Partajează Postat August 9, 2014 Ok, am rasfoit documentatia unui lcd si m-am prins ce e cu caracterele alea.Ce se intampla daca incerci sa afisezi numai 80% fara simbolurile definite de tine? Link spre comentariu
aetius Postat August 9, 2014 Autor Partajează Postat August 9, 2014 //Conexiuni LCDsbit LCD_RS at RB1_bit;sbit LCD_EN at RB3_bit;sbit LCD_D4 at RB4_bit;sbit LCD_D5 at RB5_bit;sbit LCD_D6 at RB6_bit;sbit LCD_D7 at RB7_bit;sbit LCD_RS_Direction at TRISB1_bit;sbit LCD_EN_Direction at TRISB3_bit;sbit LCD_D4_Direction at TRISB4_bit;sbit LCD_D5_Direction at TRISB5_bit;sbit LCD_D6_Direction at TRISB6_bit;sbit LCD_D7_Direction at TRISB7_bit; unsigned int adc_rd, diff;unsigned long int BarSegmentNum;char adcprint, i, ip; void main(){ INTCON = 1; // Dezactivare intreruperi TRISA = 0x03; // RA0, setate ca intrare Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear LCD Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off ADC_Init(); while(1) { adc_rd = ADC_Get_Sample(0); // Get ADC value from 1st channel if (diff != adc_rd) { Lcd_out(1,1," "); Lcd_out(2,1," "); Lcd_out(2,8,"BATTERY"); if (adc_rd <82) { Lcd_out(1,1,"10%"); Lcd_out(1,7,"LOW"); } if ((adc_rd >82) && (adc_rd <164)) { Lcd_out(1,1,"20%"); Lcd_out(1,7,"LOW"); } if ((adc_rd > 164) && (adc_rd < 246)) { Lcd_out(1,1,"30%"); Lcd_out(1,7,"CHARGING"); } if ((adc_rd > 246) && (adc_rd < 328)) { Lcd_out(1,1,"40%"); Lcd_out(1,7,"CHARGING"); } if ((adc_rd > 328) && (adc_rd < 410)) { Lcd_out(1,1,"50%"); Lcd_out(1,7,"CHARGING"); } if ((adc_rd > 410) && (adc_rd < 492)) { Lcd_out(1,1,"60%"); Lcd_out(1,7,"CHARGING"); } if ((adc_rd > 492) && (adc_rd < 574)) { Lcd_out(1,1,"70%"); Lcd_out(1,7,"CHARGING"); } if ((adc_rd > 574) && (adc_rd < 656)) { Lcd_out(1,1,"80%"); Lcd_out(1,7,"CHARGING"); } if ((adc_rd > 656) && (adc_rd < 738)) { Lcd_out(1,1,"90%"); Lcd_out(1,7,"CHARGING"); } if ((adc_rd > 738) && (adc_rd < 778)) { Lcd_out(1,1,"100%"); Lcd_out(1,7,"CHARGED"); } if (adc_rd > 778) { Lcd_out(1,1,""); Lcd_out(1,7,"CHARGED"); } } Delay_ms(1000); // Stabilize LCD display diff = adc_rd; } } am sters tot ce tinea de caracterele definite de mine(asta a mai ramas din cod) si tot asa afiseaza 80% in loc de 80% CHARGING in rest afiseaza ok Link spre comentariu
Liviu M Postat August 10, 2014 Partajează Postat August 10, 2014 Sorry, eu nu mai am idei. Una totusi a mai ramas: face la fel si in montaj, sau doar in simulator? Daca e doar in simulator, incearca si in montaj, sa nu aibe proteus probleme cu vreun grup de caractere, ceva. Link spre comentariu
aetius Postat August 10, 2014 Autor Partajează Postat August 10, 2014 (editat) Lcd_out(1,1," "); Lcd_out(2,1," "); liniile de mai sus ce fac?? face numai in simulare afiseaza doar 80% fara CHARGING restul e OK s fara caracterele setate de mine tot asa...o sa mai citesc. Editat August 10, 2014 de aetius Link spre comentariu
Liviu M Postat August 10, 2014 Partajează Postat August 10, 2014 Liniile de care intrebi scriu "nimic" (blankuri, pauze) pe randul 1, coloana 1 (primul) si pe randul 2, de la coloana 1 al doilea. Cu alte cuvinte sterg ce e deja afisat acolo. Link spre comentariu
aetius Postat August 10, 2014 Autor Partajează Postat August 10, 2014 o sa incerc sa fac montajul... multumesc de ajutor Link spre comentariu
aetius Postat August 11, 2014 Autor Partajează Postat August 11, 2014 (editat) am facut montajul...si tot asa afiseaza "70% charging" -"80% "-"90% charging" nu vrea la 80% sa afiseze charging nu mai am idei... Editat August 11, 2014 de aetius Link spre comentariu
Liviu M Postat August 11, 2014 Partajează Postat August 11, 2014 Cat de mare e programul (raportat la memoria picului)? Link spre comentariu
ventzel Postat August 11, 2014 Partajează Postat August 11, 2014 (editat) Ti-am corectat un pic programu sa mearga dupa acelasi model. Problema ii ca la functia Lcd_out siru de caractere afisat ii considerat variabila si ii bagat automat in ram. Cred ca si in cazu asta Mikroc nu lucreaza bine cu paginarea la RAM pe PIC16F, problema destul de des intalnita si singura solutie ii adresarea manuala a bankurilor diferite de bank0. //Conexiuni LCDsbit LCD_RS at RB1_bit;sbit LCD_EN at RB3_bit;sbit LCD_D4 at RB4_bit;sbit LCD_D5 at RB5_bit;sbit LCD_D6 at RB6_bit;sbit LCD_D7 at RB7_bit;sbit LCD_RS_Direction at TRISB1_bit;sbit LCD_EN_Direction at TRISB3_bit;sbit LCD_D4_Direction at TRISB4_bit;sbit LCD_D5_Direction at TRISB5_bit;sbit LCD_D6_Direction at TRISB6_bit;sbit LCD_D7_Direction at TRISB7_bit;unsigned int adc_rd, diff;unsigned long int BarSegmentNum;char adcprint, i, ip;void main(){ INTCON = 1; // Dezactivare intreruperi TRISA = 0x03; // RA0, setate ca intrare Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear LCD Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off ADC_Init(); while(1) { adc_rd = ADC_Get_Sample(0); // Get ADC value from 1st channel if (diff != adc_rd) { Lcd_out(1,1," "); Lcd_out(2,1," "); Lcd_out(2,8,"BATTERY"); if (adc_rd <82) { Lcd_out(1,1,"10%"); //Lcd_out(1,7,"LOW"); } else if ((adc_rd <164)) { Lcd_out(1,1,"20%"); //Lcd_out(1,7,"LOW"); } else if ((adc_rd < 246)) { Lcd_out(1,1,"30%"); //Lcd_out(1,7,"CHARGING"); } else if ((adc_rd < 328)) { Lcd_out(1,1,"40%"); //Lcd_out(1,7,"CHARGING"); } else if ((adc_rd < 410)) { Lcd_out(1,1,"50%"); // Lcd_out(1,7,"CHARGING"); } else if ((adc_rd < 492)) { Lcd_out(1,1,"60%"); // Lcd_out(1,7,"CHARGING"); } else if ((adc_rd < 574)) { Lcd_out(1,1,"70%"); //Lcd_out(1,7,"CHARGING"); } else if ((adc_rd < 656)) { Lcd_out(1,1,"80%"); //Lcd_out(1,7,"CHARGING"); } else if ((adc_rd < 738)) { Lcd_out(1,1,"90%"); //Lcd_out(1,7,"CHARGING"); } else if ((adc_rd < 778)) { Lcd_out(1,1,"100%"); // Lcd_out(1,7,"CHARGED"); } else { Lcd_out(1,1,""); //Lcd_out(1,7,"CHARGED"); } if ((adc_rd <164)) {Lcd_out(1,7,"LOW"); } else if ((adc_rd < 738)) {Lcd_out(1,7,"CHARGING"); } else {Lcd_out(1,7,"CHARGED"); } } Delay_ms(1000); // Stabilize LCD display diff = adc_rd; }} Editat August 11, 2014 de ventzel Link spre comentariu
Mihai Popa Postat August 11, 2014 Partajează Postat August 11, 2014 Ar mai fi o solutie: foloseste o versiune mai veche de MikroC, nu ultima... Am observat ca ultima varianta de compilator (versiunea 6) are ceva probleme...si MikroBasic si MikroC. Link spre comentariu
aetius Postat August 12, 2014 Autor Partajează Postat August 12, 2014 pentru : @Liviu M 0 1144 Used RAM (bytes): 121 (34%) Free RAM (bytes): 231 (66%) 0 1144 Used ROM (program words): 1347 (16%) Free ROM (program words): 6845 (84%) @ventzel Multumesc ... functioneaza Am adaugat si caracterele speciale si urmeaza sa adaug o protectie pentru baterie. @Mihai Popa Folosesc versiunea 5.6.1 Urmeaza un alt proiect SWR-metro. Multumesc de ajutor, tuturor. Link spre comentariu
Liviu M Postat August 12, 2014 Partajează Postat August 12, 2014 Ti-am corectat un pic programuVarianta corecta de abordat problema. Link spre comentariu
Postări Recomandate
Creează un cont sau autentifică-te pentru a adăuga comentariu
Trebuie să fi un membru pentru a putea lăsa un comentariu.
Creează un cont
Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!
Înregistrează un nou contAutentificare
Ai deja un cont? Autentifică-te aici.
Autentifică-te acum