Sari la conținut

mducu

Members
  • Număr conținut

    31
  • Înregistrat

  • Ultima Vizită

  • Zile Câștigate

    4

mducu a câștigat ziua ultima dată pe Februarie 19

mducu a avut cel mai apreciat conținut!

Reputație Comunitate

13 Good

Despre mducu

  • Rang
    Membru
  • Dată Naștere 11.02.1985

Profile Fields

  • Oras
    Galati

Vizitatori Recenți Profil

746 vizualizari profil
  1. mducu

    Alimentator 0-30V 10A

    Salut, atasez fisierul cu documentatia completa pentru a putea fi reconstruita. Fisier: ALIMENTATORE 0 30V 10A (MK 3965) di Giulio Buseghin.pdf
  2. mducu

    Schema amplituner Yamaha R30

    Pai e relativ simplu de aflat: Cu un multimetru (pozitionat pe rezistenta Ω) masori infasurarile, infasurarile cu valoarea cea mai mare este primarul. Izolezi firele adaugi un stecher si o siguranta (ex. 1A) in serie (daca nu le ai deja), apoi il conectezi la retea (220vac), si masori tensiunile pe celelate infasurari (ele sunt secundarele). Cu un subler afli diametrul sarmelor de CuEm. Din tabelul de mai jos afli si curentul care poate fi suportat. Spor!
  3. In urma testelor, revin cu rezultatul final: Nu ma declar foarte multumit deoarece nu am facut decat sa testez magistrala I2C in Proteus, cum am urmarit pe internet. Pentru a functiona am adaugat un modul debugging I2C la reteaua de comunicatii, in simulari, acum afiseaza corect cu fisierul meu hex din arhiva. Am instalat versiunea 8.8 de Proteus, ca si la versiuni mai vechi, in modul de simulare ruleaza circa 40-50 de secunde apoi programul se inchide. Am incercat diferite artificii pentru a-l face mai stabil (am inchis celelalte programe, antivirus, am adus fisierul hex in fisierul sursa al Proteus-ului, schimbat cheia de licenta) fara nici un rezultat pana in momentul de fata. Am reusit sa testez si meniul (butoanele). Functioneaza dar ruleaza foarte lent simularea iar procesorul urca in 99%. Fizic proiectul garantat ruleaza fara nici o problema. Daca doriti sa il construiti de la zero, va ofer suport cu drag. Stima.
  4. mducu

    Schema amplituner Yamaha R30

    la cautari pe google dadusem de R300. Am cautat pe hifiengine si nu dispune de informatii legate de Yamaha R30. Fiind modele relativ apropiate ca an de executie, presupun ca sunt asemanatoare la nivel hardware.
  5. D-nul gsabac daca doriti sa imi trimiteti, va rog, fisierul cu simularea in proteus, o voi testa si eu. Eventual voi reface schema pe breadboard, il am la indemana. 32,768KHz este frecventa de lucru a lui IC DS1307, 8Mhz este frecventa de lucru a PIC-ului, amandoua comunica prin protocolul standard I2C. Linia de cod: I2C1_Init(100000); // initialize I2C 100000 face referire la frecventa de lucru (clock-ul) la care se doreste a rula protocolul I2C. La mine a functionat corect cu frecventa aleasa de 100000 hz.
  6. mducu

    Schema amplituner Yamaha R30

    Salut, daca te refereai la Receiver Yamaha R-300: Fisier: Yamaha_r-300_service.pdf
  7. Intr-adevar, interesul meu a fost sa proiectez functia de modificare ora si inregistrare in memoria chipului, la acel moment a fost suficient sa folosesc un integrat dedicat, precizia m-a interesat mai putin in timp, dar cu siguranta de inbunatatiri mereu este loc. DS3231 are un oscilator pentru a compensa termic dar e si de poate 3 ori mai mare fizic. Vreau sa punctez doar faptul ca aproape intotdeauna exista o balanta intre calitate si practicabilitate.
  8. Multumesc prog. M-am jucat cu el vreo 6 luni dupa care l-am demontat. In perioada mentionata nu mi-a lasat impresia ca afiseaza eronat valorile. Pe perioade lungi de timp e posibil sa introduca erori, conteza mult si calitatea bateriei de 3 volti. Ca si consum undeva pe la 65-80mA cred, deoarece aveam si acel display cu backlight care consuma destul.
  9. ...revin cu fisierele originale pentru sursa de mai sus. Arhiva: Sursa Stabilizata AM215.zip
  10. Salut, in continuare voi prezenta un proiect tot cu ceas dar de aceasta data informatia va fi afisata pe un display cu digiti (7 segmente), controlat de catre driver-ul serial IC MAX 7219. S-a dorit: Realizarea unui ceas de precizie cu functie de memorare, chiar daca circuitul nu este alimentat. Adaugarea unui senzor de temperatura (DS18B20) cu o precizie de masurare de 0,1 grade Celsius. Afisarea informatiei pe un display cu 8 digiti (7 segmente). Sa realizat un panou cu 3 butoane prin care ceasul poate intra in functia de modificare ora si minut (RB0 Enter, RB1 + Minut, RB2 + Ora). Microcontrollerul ales este pic16f876a dar poate fi folosit oricare altul cu conditia sa suporte protocoalele de comunicatie cu celelate integrate. Limbajul de programare este Mikroc Pro for PIC. Comunicatia intre microcontroller si circuitul de ceas este asigurata prin protocolul I2C. Comunicatia intre microcontroller si max7219 este asigurata prin protocolul SPI. Schema electronica este realizata pe o placa de test "breadboard" cu 2420 de gauri. Circuitul de ceas este proiectat separat pe un pcb. Pcb-ul cu cei 8 digit si MAX7219 este achizitionata deasemenea, separat. Schema electronica: Schema electronica in format pdf: Real Time Clock DS1307 & DS18B20 & MAX7219 & PIC16F876A [+Meniu Setari] Explicatia schemei electronice: Butonul S1 asigura resetul intregului circuit, R1 este rezistenta de pull-up pentru butonul S1. Cristalul de cuarț folosit este de 8 MHz. Conectorul ICSP este folosit pentru a programa microcontroller-ul (eu folosesc PicKit2/3). R1,R3-R5,R10 sunt rezistente de pull-up. Dioda D1 are rol de protectie. Cele trei butoane au rol de: incrementare ora, incrementare minut, enter. Comunicatia intre circuitul DS1307 si placa "breadboard" este stabilita prin cinci pini astfel (GND, SQW, SCL, SDA, 5VDC). Nu am folosit in acest proiect functia pinului SQW. Am folosit o baterie de 3vcc pentru a asigura functionarea clock-ului intern al IC-ului ds1307, chiar daca acesta nu este alimentat. Comunicatia intre circuitul max7219 si microcontroller este stabilita prin pinii RC0 (CS),RC1 (CLK) si RC2 (MOSI) folositi pentru protocolul software-spi. Pinul RC7 asigura comunicatia cu senzorul de temperatura DS18B20. Grupul de condensatoare C8-C11 au rol de filtrare pe ramura de alimentare.De preferat fiecare grup sa fie cat mai aproape de IC. Software-ul: /* '******************************************************************************* ' Project name: Real Time Clock [DS1307 with Set Functions] & DS18B20 & max7219 ' Description: ' With this experiment we wish to succed the next task: ' Display on 6 digits with 7 segment leds, the clock and the room ' temperature (in Celsius Degree). ' Setting the time helped by three buttons: hours, minutes and enter. ' ' The sign "-" to the negative temperature and the hundreds for the ' temperature value are displayed just if are used. ' The time is displayed 5 second then he display the temperature value ' in Celsius Degrees for other 5 seconds and the loop goes to infinite. ' Our clock, displays as shown below(but just in display time, ' not in set mode). ' Ex. of viewing in 7 segment display,6 digits : ' Display time, mode: Display temperature mode: ' __________ _________ ' |__24.59.59| ~5 sec delay |____23.6C| ' ' Hardware configuration is: ' IC ds1307 is connected with our microcontroller trough RC3=SCL, ' RC4=SDA (I2C Connections), ' max7219 as follow:(CS at RC0, CLK at RC1 and MOSI(SDO) at RC2) ' DS18B20 is assigned to RC7, ' RB0,RB1 and RB3 are assigned to the buttons ' Buttons Menu: RB0= Enter, (It goes to set functions or exit from set functions) ' RB1= Minutes, ' RB2= Hours, ' ' Written by: ' Aureliu Raducu Macovei, 2014. ' Test configuration: ' MCU: PIC16F876A; ' Test.Board: WB-106 Breadboard 2420 dots; ' SW: MikroC PRO for PIC 2013 (version v6.4.0); ' Configuration Word: ' Oscillator: HS (8Mhz)on pins 9 and 10; ' Watchdog Timer: OFF; ' Power up Timer: OFF; ' Browun Out Detect: ON; ' Low Voltage Program: Disabled; ' Data EE Read Protect: OFF; ' Flash Program Write: Write Protection OFF; ' Background Debug: Disabled; ' Code Protect: OFF '******************************************************************************* */ // Software SPI module connections for max7219 sbit SoftSpi_SDI at RC6_bit; sbit SoftSpi_SDO at RC2_bit; // MOSI sbit SoftSpi_CLK at RC1_bit; sbit Chip_Select at RC0_bit; sbit SoftSpi_SDI_Direction at TRISC6_bit; sbit SoftSpi_SDO_Direction at TRISC2_bit; sbit SoftSpi_CLK_Direction at TRISC1_bit; sbit Chip_Select_Direction at TrisC0_bit; // End Software SPI module connections for max7219 const unsigned short TEMP_RESOLUTION = 12; //This is resolution for ds18b20 unsigned temp; unsigned sec, min1, hr, week_day, day, mn, year; unsigned short mask(unsigned short num) { switch (num) // Define switch cases { case 0 : return 0x7E; // 0 for those values please study the datasheet max7219 case 1 : return 0x30; // 1 case 2 : return 0x6D; // 2 case 3 : return 0x79; // 3 case 4 : return 0x33; // 4 case 5 : return 0x5B; // 5 case 6 : return 0x5F; // 6 case 7 : return 0x70; // 7 case 8 : return 0x7F; // 8 case 9 : return 0x7B; // 9 case 10 : return 0x01; // Symbol '-' case 11 : return 0x00; // Blank case 12 : return 0x80; // Comma "," symbol case 13 : return 0x43; // C } //case end } void max7219_init() { Chip_Select = 0; // SELECT MAX Soft_Spi_write(0x09); // Decode-Mode Register Soft_Spi_write(0x00); // No decode for digits 7–0 Chip_Select = 1; // DESELECT MAX Chip_Select = 0; // SELECT MAX Soft_Spi_write(0x0A); // Intensity Register Format Soft_Spi_write(0x01); // Segment luminosity intensity set to 3/32 Chip_Select = 1; // DESELECT MAX Chip_Select = 0; // SELECT MAX Soft_Spi_write(0x0B); // Scan-Limit Register Format Soft_Spi_write(0x05); // Display digits 0 1 2 3 4 5 Chip_Select = 1; // DESELECT MAX Chip_Select = 0; // SELECT MAX Soft_Spi_write(0x0C); // Shutdown Register Format Soft_Spi_write(0x01); // Normal Operation Chip_Select = 1; // DESELECT MAX Chip_Select = 0; // SELECT MAX Soft_Spi_write(0x00); // No-Op Soft_Spi_write(0xFF); // No test Chip_Select = 1; // DESELECT MAX } char minute2,hour2; void max7219_display_set_mode(unsigned minute2, unsigned hour2) { Chip_Select = 0; // select max7219 Soft_Spi_write(6); // digit 6 Soft_Spi_write(mask((hour2/10)%10)); // assign tens of hours Chip_Select = 1; // deselect max7219 Chip_Select = 0; // select max7219 Soft_Spi_write(5); // digit 5 Soft_Spi_write ((mask(hour2%10))+ mask(12)); // assign units of hours Chip_Select = 1; // deselect max7219 Chip_Select = 0; // select max7219 Soft_Spi_write(4); // digit 4 Soft_Spi_write(mask((minute2/10)%10)); // assign tens of minutes Chip_Select = 1; // deselect max7219 Chip_Select = 0; // select max7219 Soft_Spi_write(3); // digit 3 Soft_Spi_write((mask(minute2%10))+mask(12)); // assign units of minutes Chip_Select = 1; // deselect max7219 Chip_Select = 0; // select max7219 Soft_Spi_write(2); // digit 2 Soft_Spi_write (0); // set as blank Chip_Select = 1; // deselect max7219 Chip_Select = 0; // select max7219 Soft_Spi_write(1); // digit 1 Soft_Spi_write (0); // set as blank Chip_Select = 1; // deselect max7219 } void max7219_display (unsigned sec, unsigned min, unsigned hr) { Chip_Select = 0; // select max7219 Soft_Spi_write(6); // digit 6 Soft_Spi_write(mask((hr/10)%10)); // assign tens of hours Chip_Select = 1; // deselect max7219 Chip_Select = 0; // select max7219 Soft_Spi_write(5); // digit 5 Soft_Spi_write ((mask(hr%10))+ mask(12)); // assign units of hours Chip_Select = 1; // deselect max7219 Chip_Select = 0; // select max7219 Soft_Spi_write(4); // digit 4 Soft_Spi_write(mask((min/10)%10)); // assign tens of minutes Chip_Select = 1; // deselect max7219 Chip_Select = 0; // select max7219 Soft_Spi_write(3); // digit 3 Soft_Spi_write((mask(min%10))+mask(12)); // assign units of minutes Chip_Select = 1; // deselect max7219 Chip_Select = 0; // select max7219 Soft_Spi_write(2); // digit 2 Soft_Spi_write (mask((sec/10)%10)); // assign tens of seconds Chip_Select = 1; // deselect max7219 Chip_Select = 0; // select max7219 Soft_Spi_write(1); // digit 1 Soft_Spi_write (mask(sec%10)); // assign units of seconds Chip_Select = 1; // deselect max7219 } //-----Reads time and date information from RTC (DS1307) void Read_Time(unsigned *sec, unsigned *min, unsigned *hr, unsigned *week_day, unsigned *day, unsigned *mn, unsigned *year) { I2C1_Start(); I2C1_Wr(0xD0); I2C1_Wr(0); I2C1_Repeated_Start(); I2C1_Wr(0xD1); *sec =I2C1_Rd(1); *min =I2C1_Rd(1); *hr =I2C1_Rd(1); *week_day =I2C1_Rd(1); *day =I2C1_Rd(1); *mn =I2C1_Rd(1); *year =I2C1_Rd(0); I2C1_Stop(); }//~ //-----------------start write time routine------------------ void Write_Time(unsigned minute, unsigned hour) { unsigned tmp1, tmp2; tmp1 = minute / 10; // assign values from variables tmp2 = minute % 10; // assign values from variables minute = tmp1 * 16 + tmp2; // assign values from variables tmp1 = hour / 10; // assign values from variables tmp2 = hour % 10; // assign values from variables hour = tmp1 * 16 + tmp2; // assign values from variables I2C1_Start(); // issue start signal I2C1_Wr(0xD0); // address DS1307 I2C1_Wr(0); // start from word at address (REG0) I2C1_Wr(0x80); // write $80 to REG0. (pause counter + 0 sec) I2C1_Wr(minute); // write minutes word to (REG1) I2C1_Wr(hour); // write hours word (24-hours mode)(REG2) I2C1_Wr(0x00); // write 6 - Saturday (REG3) I2C1_Wr(0x00); // write 14 to date word (REG4) I2C1_Wr(0x00); // write 5 (May) to month word (REG5) I2C1_Wr(0x00); // write 01 to year word (REG6) I2C1_Wr(0x80); // write SQW/Out value (REG7) I2C1_Stop(); // issue stop signal I2C1_Start(); // issue start signal I2C1_Wr(0xD0); // address DS1307 I2C1_Wr(0); // start from word at address 0 I2C1_Wr(0); // write 0 to REG0 (enable counting + 0 sec) I2C1_Stop(); // issue stop signal } //-----------------end write time routine------------------ //-------------------- Formats date and time void Transform_Time(unsigned *sec, unsigned *min, unsigned *hr, unsigned *week_day, unsigned *day, unsigned *mn, unsigned *year) { *sec = ((*sec & 0x70) >> 4)*10 + (*sec & 0x0F); *min = ((*min & 0xF0) >> 4)*10 + (*min & 0x0F); *hr = ((*hr & 0x30) >> 4)*10 + (*hr & 0x0F); *week_day =(*week_day & 0x07); *day = ((*day & 0xF0) >> 4)*10 + (*day & 0x0F); *mn = ((*mn & 0x10) >> 4)*10 + (*mn & 0x0F); *year = ((*year & 0xF0)>>4)*10+(*year & 0x0F); }//~ void blink_min() { Chip_Select = 0; // select max7219 Soft_Spi_write(4); // digit 4 Soft_Spi_write(0); // set as blank Chip_Select = 1; // deselect max7219 Chip_Select = 0; // select max7219 Soft_Spi_write(3); // digit 3 Soft_Spi_write(0); // set as blank Chip_Select = 1; delay_ms(50); // 50ms delay max7219_display_set_mode(minute2,hour2); // display those values delay_ms(50); // 50ms delay } void blink_hr() { Chip_Select = 0; // select max7219 Soft_Spi_write(6); // digit 6 Soft_Spi_write(0); // set as blank Chip_Select = 1; // deselect max7219 Chip_Select = 0; // select max7219 Soft_Spi_write(5); // digit 5 Soft_Spi_write(0); // set as blank Chip_Select = 1; // deselect max7219 delay_ms(50); // 50ms delay max7219_display_set_mode(minute2,hour2); // display those values delay_ms(50); // 50ms delay } char setuptime=0; unsigned count=0; void Press_Switch() { if(button(&portb,0,1,0)) // check if button RB0 is pressed { Delay_ms(200); setuptime = !setuptime; // switch that value; if(setuptime) { hour2=hr; minute2=min1; max7219_display_set_mode(minute2,hour2); // display those values } else { hr=hour2; min1=minute2; Write_Time(min1,hr); max7219_display_set_mode(minute2,hour2); } } if(Setuptime) { if(button(&portb,1,1,0)) { Delay_ms(150); minute2++; if(minute2 > 59) minute2=0; blink_min(); } if(button(&portb,2,1,0)) { Delay_ms(150); hour2++; if(hour2 > 23) hour2=0; blink_hr(); } } } // Starts ds18b20 declarations void ds18b20(unsigned int temp2write) { const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8; unsigned temp_whole; unsigned int temp_fraction; unsigned short isNegative = 0x00; // Check if temperature is negative if (temp2write & 0x8000) { temp2write = ~temp2write + 1; isNegative = 1; } // Extract temp_whole temp_whole = temp2write >> RES_SHIFT ; // Extract temp_fraction and convert it to unsigned int temp_fraction = temp2write << (4-RES_SHIFT); temp_fraction &= 0x000F; temp_fraction *= 625; // 625 for ds18b20 and 5000 for ds1820; Chip_Select = 0; // select max7219 Soft_Spi_write(1); // digit 1 Soft_Spi_write(mask(13)); // write C symbol Chip_Select = 1; // deselect max7219 Chip_Select = 0; // select max7219 Soft_Spi_write(2); // Set digit number 3 Soft_Spi_write(mask(temp_fraction /1000)); // assigne as fraction Chip_Select = 1; // deselect max7219 Chip_Select = 0; // select max7219 Soft_Spi_write(3); // Set digit number 3 Soft_Spi_write((mask(temp_whole%10))+mask(12)); // Assigne as ones Chip_Select = 1; // deselect max7219 Chip_Select = 0; // select max7219 Soft_Spi_write(4); // Set digit number 4 Soft_Spi_write (mask((temp_whole/10)%10)); // Assigne as tens Chip_Select = 1; // deselect max7219 if (isNegative == 1) { Chip_Select = 0; // select max7219 Soft_Spi_write(5); // Set digit number 5 Soft_Spi_write(mask(10)); // Assigne as symbol "-" Chip_Select = 1; // deselect max7219 } else { if(isNegative ==0 && temp_whole/100==0) { Chip_Select = 0; // select max7219 Soft_Spi_write(5); // Set digit number 5 Soft_Spi_write(mask(11)); // Assign as blank Chip_Select = 1; // deselect max7219 } else { Chip_Select = 0; // select max7219 Soft_Spi_write(5); // Set digit number 5 Soft_Spi_write(mask(temp_whole/100)); // Assign the hundreds Chip_Select = 1; // deselect max7219 } } Chip_Select = 0; // select max7219 Soft_Spi_write(6); // Set digit number 6 Soft_Spi_write(0); // Assign value 0 Chip_Select = 1; // deselect max7219 }// End ds18b20 declarations void interrupt() { if(setuptime) count=0; else count++; // Interrupt causes count to be incremented by 1 TMR0 = 0; // Timer TMR0 is returned its initial value INTCON = 0x20; // Bit T0IE is set, bit T0IF is cleared } void main() { CMCON |= 7; // Disable Comparators OPTION_REG = 0x84; // Prescaler Rate Selected at 1:32; TMR0 = 0; // Reset timer; INTCON = 0xA0; // Disable interrupt PEIE,INTE,RBIE,T0IE Chip_Select_Direction = 0; // Set RC0 pin as output Soft_Spi_init(); // Initialize software SPI module max7219_init(); // initialize max7219 I2C1_Init(100000); // initialize I2C while (1) // and here, our while loope { Press_Switch(); if(!setuptime) { if(count<=1400) // ~ 5 seconds { Read_Time(&sec,&min1,&hr,&week_day,&day,&mn,&year); // read time from RTC(DS1307) Transform_Time(&sec,&min1,&hr,&week_day,&day,&mn,&year); // format date and time max7219_display(sec,min1, hr); } else { if(count>1400) // ~ 5 seconds { //Perform temperature reading Ow_Reset(&PORTC, 7); // Onewire reset signal Ow_Write(&PORTC, 7, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTC, 7, 0x44); // Issue command CONVERT_T Ow_Reset(&PORTC, 7); Ow_Write(&PORTC, 7, 0xCC); // Issue command SKIP_ROM Ow_Write(&PORTC, 7, 0xBE); // Issue command READ_SCRATCHPAD temp = Ow_Read(&PORTC, 7); // Next Read Temperature and Read Byte 0 from Scratchpad // Then read Byte 1 from Scratchpad and shift 8 bit left and add the Byte 0 temp = (Ow_Read(&PORTC, 7) << 8) + temp; ds18b20(temp); //Format and display result on digits. } } if(count>2800) count = 0; } } } Demonstratia practica: ...si un filmulet: Recomandari: La prima impresie codul pare stufos dar citit si interpretat pe parti va fi mult mai usor de inteles. Stima.
  11. Salut, voi prezenta doua dintre proiectele mele, concepute cu ceva timp in urma, dar de actualitate, pentru a exemplifica modul de proiectare si programare folosind microcontrollere PIC. S-a dorit: Realizarea unui ceas de precizie cu functie de memorare, chiar daca circuitul nu este alimentat. Adaugarea unui senzor de temperatura (DS18B20) cu o precizie de masurare de 0,1 grade Celsius. Afisarea pe un display cu 2 linii a cate 16 caractere, compatibil cu standardul HD44780. Sa realizat un meniu prin care informatiile sunt modificate si inregistrate in IC DS1307. Ca si microcontroller s-a ales pic16f876a (dar poate fi folosit oricare altul). Limbajul de programare ales este Mikroc Pro for PIC. Comunicatia intre microcontroller si circuitul de ceas este asigurata prin protocolul I2C. Patru butoane ne permit explorarea meniului. Intregul circuit este realizat pe o placa de test "breadboard" cu 2420 de gauri, mai putin circuitul de ceas care este proiectat separat pe o placa de circuit imprimat. Schema electronica: Explicatia schemei electronice: Butonul S1 asigura resetul intregului circuit, R1 este rezistenta de pull-up pentru butonul S1. Cristal de cuarț folosit este de 8 MHz. Conectorul ICSP este folosit pentru a programa microcontroller-ul (eu folosesc PicKit2/3). Rezistenta multitura R7 este folosita pentru a regla contrastul display-ului LCD. R6 ajusteaza curentul de consum prin ledurile care asigura iluminarea display-ului. R2-R5, R8-R10 sunt rezistențe de pull-up. Dioda D1 are rol de protectie (alimentez circuitul si cu programatorul si s-a dorit evitarea diferentei de potential in punctele de alimentare pozitive). Cele patru butoane au rol de: Incrementare, Decrementare, Schimbare Pozitie Cursor si Enter. Comunicatia intre circuitul DS1307 si placa "breadboard" este stabilita prin cinci pini astfel (GND, SQW, SCL, SDA, 5VDC). Nu am folosit aici pinul SQW. Am folosit o baterie de 3vcc pentru a asigura functionarea clock-ului intern al IC-ului ds1307, chiar daca acesta nu este alimentat. Diagrama de timp a comunicatiei I2C transmise de DS1307: Modelul semnalului la transferul de date: Diagrama bloc: Software-ul: /* '******************************************************************************* ' Project name: Real Time Clock [DS1307 with Set Functions] & DS18B20 ' Description: ' Trough the current experiment we wish to succed the next task: ' Display on LCD 2x16 character the clock and room temperature. ' Setting trough four buttons: the minutes, hours, date of the month, ' month, day of the week, and year. ' ' Our clock displays as shown below(but just in display time, ' not in set mode). ' Ex. of viewing on 2x16 LCD characters: ' Display time, mode: Set time, mode (cursor on): ' ------------------ ------------------ ' |Sat, 03 Dec 2011| |Sat, 03 12 2011| ' |21:32:03 +26,1*C| |21:32:03 | ' ------------------ ------------------ ' ' Hardware configuration is: ' IC ds1307 is connected with our microcontroller trough RC3=SCL, ' RC4=SDA (I2C Connections), RB0,RB1,RB4-RB7 are assigned to LCD (2x16) ' DS18B20 is assigned to RC7, ' Buttons Menu: RC0= Increment value, ' RC1= Decrement value, ' RC2= Change cursor position, ' RC5= Enter.(It goes to set functions or exit from set ' functions) ' Written by: ' Aureliu Raducu Macovei, 2014. ' Test configuration: ' MCU: PIC16F876A; ' Test.Board: WB-106 Breadboard 2420 dots; ' SW: MikroC PRO for PIC 2013 (version v6.0.0); ' Configuration Word: ' Oscillator: HS (8Mhz)on pins 9 and 10; ' Watchdog Timer: OFF; ' Power up Timer: OFF; ' Browun Out Detect: ON; ' Low Voltage Program: Disabled; ' Data EE Read Protect: OFF; ' Flash Program Write: Write Protection OFF; ' Background Debug: Disabled; ' Code Protect: OFF '******************************************************************************* */ // LCD module connections sbit LCD_RS at RB0_bit; // LCD_RS assigned to PORT RB0; sbit LCD_EN at RB1_bit; // LCD_EN assigned to PORT RB1; sbit LCD_D4 at RB4_bit; // LCD_D4 assigned to PORT RB4; sbit LCD_D5 at RB5_bit; // LCD_D5 assigned to PORT RB5; sbit LCD_D6 at RB6_bit; // LCD_D6 assigned to PORT RB6; sbit LCD_D7 at RB7_bit; // LCD_D7 assigned to PORT RB7; sbit LCD_RS_Direction at TRISB0_bit; // LCD_RS assigned to TRIS B0; sbit LCD_EN_Direction at TRISB1_bit; // LCD_EN assigned to TRIS B1; sbit LCD_D4_Direction at TRISB4_bit; // LCD_D4 assigned to TRIS B4; sbit LCD_D5_Direction at TRISB5_bit; // LCD_D5 assigned to TRIS B5; sbit LCD_D6_Direction at TRISB6_bit; // LCD_D6 assigned to TRIS B6; sbit LCD_D7_Direction at TRISB7_bit; // LCD_D7 assigned to TRIS B7; // End LCD module connections unsigned char sec,min1,hr,week_day,day,mn,year; //--------------------- Reads time and date information from RTC (DS1307) void Read_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year) { I2C1_Start(); // Issue start signal I2C1_Wr(0xD0); // Address DS1307, see DS1307 datasheet I2C1_Wr(0); // Start from address 0 I2C1_Repeated_Start(); // Issue repeated start signal I2C1_Wr(0xD1); // Address DS1307 for reading R/W=1 *sec =I2C1_Rd(1); // Read seconds byte *min =I2C1_Rd(1); // Read minutes byte *hr =I2C1_Rd(1); // Read hours byte *week_day =I2C1_Rd(1); // Read week day byte *day =I2C1_Rd(1); // Read day byte *mn =I2C1_Rd(1); // Read mn byte *year =I2C1_Rd(0); // Read Year byte I2C1_Stop(); // Issue stop signal } //-----------------write time routine------------------ void Write_Time(char minute, char hour ,char weekday,char day,char month,char year) { char tmp1, tmp2; tmp1 = minute / 10; //Write tens of minute tmp2 = minute % 10; //Write unit of minute minute = tmp1 * 16 + tmp2; //Includes all value tmp1 = hour / 10; //Write tens of hour tmp2 = hour % 10; //Write unit of hour hour = tmp1 * 16 + tmp2; //Includes all value tmp1 = weekday / 10; //Write tens of weekday tmp2 = weekday % 10; //Write unit of weekday weekday = tmp1 *16 +tmp2; //Includes all value tmp1 = day / 10; //Write tens of day tmp2 = day % 10; //Write unit of day day = tmp1 *16 +tmp2; //Includes all value tmp1 = month / 10; //Write tens of month tmp2 = month % 10; //Write unit of month month = tmp1 *16 +tmp2; //Includes all value tmp1 = year / 10; //Write tens of year tmp2 = year % 10; //Write unit of year year = tmp1 *16 +tmp2; //Includes all value I2C1_Start(); // issue start signal I2C1_Wr(0xD0); // address DS1307 I2C1_Wr(0); // start from word at address (REG0) I2C1_Wr(0x80); // write $80 to REG0. (pause counter + 0 sec) I2C1_Wr(minute); // write minutes word to (REG1) I2C1_Wr(hour); // write hours word (24-hours mode)(REG2) I2C1_Wr(weekday); // write 6 - Saturday (REG3) I2C1_Wr(day); // write 14 to date word (REG4) I2C1_Wr(month); // write 5 (May) to month word (REG5) I2C1_Wr(year); // write 01 to year word (REG6) I2C1_Wr(0x80); // write SQW/Out value (REG7) I2C1_Stop(); // issue stop signal I2C1_Start(); // issue start signal I2C1_Wr(0xD0); // address DS1307 I2C1_Wr(0); // start from word at address 0 I2C1_Wr(0); // write 0 to REG0 (enable counting + 0 sec) I2C1_Stop(); // issue stop signal } //-------------------- Formats date and time--------------------- void Transform_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year) { *sec = ((*sec & 0x70) >> 4)*10 + (*sec & 0x0F); *min = ((*min & 0xF0) >> 4)*10 + (*min & 0x0F); *hr = ((*hr & 0x30) >> 4)*10 + (*hr & 0x0F); *week_day =(*week_day & 0x07); *day = ((*day & 0xF0) >> 4)*10 + (*day & 0x0F); *mn = ((*mn & 0x10) >> 4)*10 + (*mn & 0x0F); *year = ((*year & 0xF0)>>4)*10+(*year & 0x0F); } //------------------------Display time--------------------------- char *txt,*mny; void Display_Time(char sec, char min, char hr, char week_day, char day, char mn, char year) { switch(week_day) { case 1: txt="Mon"; break; // Monday; case 2: txt="Tue"; break; // Tuesday; case 3: txt="Wed"; break; // Wednesday; case 4: txt="Thu"; break; // Thursday; case 5: txt="Fri"; break; // Friday; case 6: txt="Sat"; break; // Saturday; case 7: txt="Sun"; break; // Sunday; } LCD_Out(1, 1,txt); LCD_chr(1, 4,','); switch(mn) { case 1: mny="Jan"; break; case 2: mny="Feb"; break; case 3: mny="Mar"; break; case 4: mny="Apr"; break; case 5: mny="May"; break; case 6: mny="Jun"; break; case 7: mny="Jul"; break; case 8: mny="Aug"; break; case 9: mny="Sep"; break; case 10: mny="Oct"; break; case 11: mny="Nov"; break; case 12: mny="Dec"; break; } Lcd_Chr(1, 6, (day / 10) + 48); // Print tens digit of day variable Lcd_Chr(1, 7, (day % 10) + 48); // Print oness digit of day variable Lcd_Out(1, 9,mny); Lcd_out(1,13,"20"); Lcd_Chr(1,15, (year / 10) + 48); // we can set year 00-99 [tens] Lcd_Chr(1,16, (year % 10) + 48); // we can set year 00-99 [ones] Lcd_Chr(2, 1, (hr / 10) + 48); Lcd_Chr(2, 2, (hr % 10) + 48); Lcd_Chr(2, 3,':'); Lcd_Chr(2, 4, (min / 10) + 48); Lcd_Chr(2, 5, (min % 10) + 48); Lcd_Chr(2, 6,':'); Lcd_Chr(2, 7, (sec / 10) + 48); Lcd_Chr(2, 8, (sec % 10) + 48); } //-------------------Display Time in Set mode-------------------- char minute1,hour1,weekday1,month1; char minute,hour,weekday,day1,month,year1; void Display_Time_SetMode() { switch(weekday1) { case 1: txt="Mon"; break; // Monday; case 2: txt="Tue"; break; // Tuesday; case 3: txt="Wed"; break; // Wednesday; case 4: txt="Thu"; break; // Thursday; case 5: txt="Fri"; break; // Friday; case 6: txt="Sat"; break; // Saturday; case 7: txt="Sun"; break; // Sunday; } LCD_Out(1, 1,txt); LCD_chr(1, 4,','); Lcd_Chr(1, 6, (day1 / 10) + 48); // Print tens digit of day variable Lcd_Chr(1, 7, (day1 % 10) + 48); // Print oness digit of day variable Lcd_chr(1,10, (month1 / 10) + 48); // Print tens digit of month variable Lcd_chr(1,11, (month1 % 10) + 48); // Print oness digit of month variable Lcd_out(1,13,"20"); Lcd_Chr(1,15, (year1 / 10) + 48); // Print tens digit of year variable Lcd_Chr(1,16, (year1 % 10) + 48); // Print oness digit of year variable Lcd_Chr(2, 1, (hour1 / 10) + 48); // Print tens digit of hour variable Lcd_Chr(2, 2, (hour1 % 10) + 48); // Print oness digit of hour variable Lcd_Chr(2, 3,':'); Lcd_Chr(2, 4, (minute1 / 10) + 48); // Print tens digit of minute variable Lcd_Chr(2, 5, (minute1 % 10) + 48); // Print oness digit of minute variable Lcd_Chr(2, 6,':'); Lcd_Chr(2, 7, (0 / 10) + 48); Lcd_Chr(2, 8, (0 % 10) + 48); } char SPos; //----------------------Move cursor routine---------------------- char index; void movecursor() { char i,moveto; if(SPos==0) lcd_cmd(_lcd_first_row); // set weekday; if(SPos==1) lcd_cmd(_lcd_first_row); // set day; if(SPos==2) lcd_cmd(_lcd_first_row); // set month; if(SPos==3) lcd_cmd(_lcd_first_row); // set year; if(SPos==4) lcd_cmd(_lcd_second_row); // set hours; if(SPos==5) lcd_cmd(_lcd_second_row); // set minutes; moveto = 2; switch(index) { case 0: moveto = 2;break; case 1: moveto = 6;break; case 2: moveto =10;break; case 3: moveto =15;break; case 4: moveto = 1;break; case 5: moveto = 4;break; } for(i=1; i<= moveto; i++) lcd_cmd(_lcd_move_cursor_right); } //------------Start Buttons routine--------------; char setuptime=0; void Press_Switch() { if(setuptime) { if(Button(&portc,2,1,0)) // If buttons at port c2 is pressed { delay_ms(200); SPos++; if(SPos>5) SPos=0; index++; if(index > 5) index=0; movecursor(); } //-----------------------------case mode to set all values--------------------- switch(SPos) { case 0: if(button(&portc,0,1,0)) // If buttons at port c0 is pressed { Delay_ms(200); weekday1++; if(weekday1 > 7) weekday1=1; Display_Time_SetMode(); index=0; movecursor(); } if(button(&portc,1,1,0)) // If buttons at port c1 is pressed { Delay_ms(200); weekday1--; if(weekday1 < 1) weekday1=7; Display_Time_SetMode(); index=0; movecursor(); } break; case 1: if(button(&portc,0,1,0)) // If buttons at port c0 is pressed { Delay_ms(200); day1++; if(day1 > 31) day1 = 1; Display_Time_SetMode(); index=1; movecursor(); } if(button(&portc,1,1,0)) // If buttons at port c1 is pressed { Delay_ms(200); day1--; if(day1 < 1) day1 = 31; Display_Time_SetMode(); index=1; movecursor(); } break; case 2: if(button(&portc,0,1,0)) // If buttons at port c0 is pressed { Delay_ms(200); month1++; if(month1 > 12) month1 = 1; Display_Time_SetMode(); index=2; movecursor(); } if(button(&portc,1,1,0)) // If buttons at port c1 is pressed { Delay_ms(200); month1--; if(month1 < 1) month1 = 12; Display_Time_SetMode(); index=2; movecursor(); } break; case 3: if(button(&portc,0,1,0)) // If buttons at port c0 is pressed { Delay_ms(200); year1++; if(year1 > 99) year1 = 1; Display_Time_SetMode(); index=3; movecursor(); } if(button(&portc,1,1,0)) // If buttons at port c1 is pressed { Delay_ms(200); year1--; if(year1 < 1) year1 = 99; Display_Time_SetMode(); index=3; movecursor(); } break; case 4: if(button(&portc,0,1,0)) // If buttons at port c0 is pressed { Delay_ms(200); hour1++; if(hour1 > 23) hour1 = 0; Display_Time_SetMode(); index=4; movecursor(); } if(button(&portc,1,1,0)) // If buttons at port c1 is pressed { Delay_ms(200); hour1--; if(hour1 > 23) hour1 = 0; Display_Time_SetMode(); index=4; movecursor(); } break; case 5: if(button(&portc,0,1,0)) // If buttons at port c0 is pressed { Delay_ms(200); minute1++; if(minute1 > 59) minute1 = 0; Display_Time_SetMode(); index=5; movecursor(); } if(button(&portc,1,1,0)) // If buttons at port c1 is pressed { Delay_ms(200); minute1--; if(minute1 > 59) minute1 = 0; Display_Time_SetMode(); index=5; movecursor(); } break; } // end "if is in switch mode" } // end "if is in setup" if(button(&portc,5,1,0)) // If buttons at port c5 is pressed { Delay_ms(200); setuptime = !setuptime; if(SetupTime) { lcd_cmd(_lcd_clear); lcd_cmd(_lcd_blink_cursor_on); weekday1=week_day; hour1=hr; minute1=min1; day1=day; month1=mn; year1=year; Display_Time_SetMode(); SPos=0; index=0; movecursor(); } else { Lcd_Cmd(_Lcd_clear); lcd_cmd(_lcd_cursor_off); weekday=weekday1; hour=hour1; minute=minute1; day=day1; month=month1; year=year1; Write_time(minute,hour,weekday,day,month,year); } } } //----------------------End Buttons Routine------------------- //------------------Temperature sensor routines--------------- const unsigned short TEMP_RESOLUTION = 12; // 9 for DS1820 and 12 for DS18B20 char *text = "000,0"; unsigned temp; void Display_Temperature(unsigned int temp2write) { const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8; char temp_whole; unsigned int temp_fraction; unsigned short isNegative = 0x00; // Check if temperature is negative if (temp2write & 0x8000) { text[0] = '-'; temp2write = ~temp2write + 1; isNegative = 1; } // Extract temp_whole temp_whole = temp2write >> RES_SHIFT ; // Convert temp_whole to characters if (!isNegative){ if (temp_whole/100) text[0] = temp_whole/100 + 48; // Extract hundreds digit else text[0] = '+'; } text[1] = (temp_whole/10)%10 + 48; // Extract tens digit text[2] = temp_whole%10 + 48; // Extract ones digit // Extract temp_fraction and convert it to unsigned int temp_fraction = temp2write << (4-RES_SHIFT); temp_fraction &= 0x000F; temp_fraction *= 625; // Convert temp_fraction to characters text[4] = temp_fraction/1000 + 48; // Extract thousands digit // Print temperature on LCD Lcd_Out(2, 10,text); lcd_chr(2, 15,0xB2); // Ascii code for degrees symbol; Lcd_chr(2, 16,'C'); // Show symbol "C" from Celsius } //----------------Read and display Temperature from DS18B20-------------- void Read18b20() { //--- Perform temperature reading Ow_Reset(&PORTC, 7); // Onewire reset signal; Ow_Write(&PORTC, 7, 0xCC); // 0xCC Issue command SKIP_ROM; Ow_Write(&PORTC, 7, 0x44); // Issue command CONVERT_T; Delay_us(700); // delay 0,7s (required for signal // processing); Ow_Reset(&PORTC, 7); // Onewire reset signal; Ow_Write(&PORTC, 7, 0xCC); // Issue command SKIP_ROM; Ow_Write(&PORTC, 7, 0xBE); // Issue command READ_SCRATCHPAD; temp = Ow_Read(&PORTC, 7); // Next Read Temperature, read Byte // 0 from Scratchpad; temp = (Ow_Read(&PORTC, 7) << 8) + temp; // Then read Byte 1 from Scratchpad // and shift 8 bit left and add the Byte 0; //--- Format and display result on Lcd Display_Temperature(temp); // Call Display_Temperature; } //------------------Temperature sensor routines--------------- void Init_Main() { CMCON |=7; //TURN OFF ANALOGUE COMPARATOR AND MAKE PORTA TO DIGITAL I/O; I2C1_Init(100000); // initialize I2C Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear LCD display Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off Display_Time(sec, min1, hr, week_day, day, mn, year); !setuptime=1; index=0; SPos=0; } //-----------------Here we have the Main Routine---------------- void main() { Init_Main(); while (1) // While loop { Read_Time(&sec,&min1,&hr,&week_day,&day,&mn,&year); // read time from RTC(DS1307) Transform_Time(&sec,&min1,&hr,&week_day,&day,&mn,&year); // Transform time Press_Switch(); // Check buttons; if(!setuptime) { Display_Time(sec, min1, hr, week_day, day, mn, year); Read18b20(); } } } Explicatiile liniilor de cod le-am lasat in limba engleza, presupun ca nu este o problema. Demonstractiile practice: ...si un filmulet: Proiectul complet (fisierele eagle si mikroc): Real Time Clock DS1307 & DS18B20 & LCD02x16 PIC16F876A Stima.
  12. mducu

    Auditie VIOTUBEAMP

    Felicitari, faina initiativa.
  13. mducu

    Votati muzica care va place.

    (New South African) Tribal House Master Mix, Mixed @432Hz Mixed By Dj Prohustlers
×

Informații Importante

Folosim cookie-uri și tehnologii asemănătoare pentru a-ți îmbunătăți experiența pe acest website, pentru a-ți oferi conținut și reclame personalizate și pentru a analiza traficul și audiența website-ului. Înainte de a continua navigarea pe www.tehnium-azi.ro te rugăm să fii de acord cu: Termeni de Utilizare.