Jump to content
ELFORUM - Forumul Electronistilor

Kreator

Membru activ
  • Content Count

    544
  • Joined

  • Last visited

Community Reputation

41 Se poate si mai bine

About Kreator

  • Rank
    Membru

Contact Methods

  • Website URL
    https://cristinastac.wordpress.com/

Profile Information

  • Locatie
    Baia Mare

Recent Profile Visitors

782 profile views
  1. ce-mi plac mie angajatii de genul asta, cand obiectivul principal nu este crearea unui proiect de calitate ci calitatea satisfactiei sefului.
  2. D4 e desenata gresit, in paralel cu primarul mai trebuie un snubber. 10A .... in vise!
  3. @fratello schema corectata Programul corectat program Ceas_MAX7219_PIC1827 ' Declarations section Const cnfgww As Byte = %11010000 'Adress for write DS3231 Const cnfgwr As Byte = %11010001 'Adress for read DS3231 const MAX7219_TEST as byte =0x0F const MAX7219_BRIGHTNESS as byte = 0x0A const MAX7219_SCAN_LIMIT as byte = 0x0B const MAX7219_DECODE_MODE as byte = 0x09 const MAX7219_SHUTDOWN as byte = 0x0C const mxbt As Byte[11] =(0, 23, 59, 31, 12, 99, 59, 23, 59, 15, 1) ' max value const mnbt As Byte[11] =(0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0) ' min value const stadrs As Byte[11] =(0, 0x02, 0x01, 0x04, 0x05, 0x06, 0x00, 0x09, 0x08, 0x0B, 0x0D) ' Adress data RTC const alfabet as byte [16] [8]= (( 30, 63, 51, 51, 51, 51, 63, 30), '0 ( 6, 14, 30, 6, 6, 6, 6, 15), '1 ( 30, 63, 35, 6, 12, 24, 63, 63), '2 ( 30, 63, 35, 14, 14, 35, 63, 30), '3 ( 6, 14, 30, 54, 54, 63, 6, 15), '4 ( 62, 63, 48, 62, 51, 3, 63, 30), '5 ( 30, 63, 48, 62, 51, 51, 63, 30), '6 ( 63, 63, 3, 6, 12, 12, 12, 12), '7 ( 30, 63, 51, 30, 51, 51, 63, 30), '8 ( 30, 63, 51, 51, 31, 3, 63, 30), '9 ( 0, 0, 0, 0, 0, 0, 0, 0), 'blank ( 0, 3, 3, 0, 0, 3, 3, 0), 'dp (120, 124, 68, 64, 64, 68, 124, 120), 'C ( 56, 109, 109, 109, 57, 1, 1, 0), '` ( 62, 63, 51, 62, 51, 51, 63, 62), 'B ( 0, 0, 27, 31, 28, 24, 24, 24)) 'r Dim CS as sbit at RB3_bit 'Chip Select pin for MAX7219 CS_Direction as sbit at TRISB3_bit Dim Soft_I2C_Sda as sbit at RB6_bit 'SDA pin for DS3231 Dim Soft_I2C_Scl as sbit at RB7_bit 'SCL pin for DS3231 Dim Soft_I2C_Sda_Direction as sbit at TRISB6_bit Dim Soft_I2C_Scl_Direction as sbit at TRISB7_bit Dim i,j, x, y, yy, bright, m, s_, z_, u, dp, str as byte Dim k, k0, k1, k4, k5, al as byte Dim flgal, flsh, x0, x1, x5, flgint, pflgint as bit Dim ma, sa, za, uua, utmp, ztmp, stmp, ltmp, rtmp, mtmp as byte[8] Dim dsp, th_dsp, h_dsp as byte[32] Dim s0, s1, m0, m1, h0, h1, ah0, ah1, am0, am1 As Byte Dim d0, d1, mo0, mo1, y0, y1, th0, th1, br1, br0 As Byte Dim btset, btmod, btvar, btmp, grc As Byte sub function I2CR(dim byref adress as byte) as byte ' Read value from RTC Soft_I2C_Start() ' Issue start signal Soft_I2C_Write(cnfgww) ' Address DS3221 datasheet Soft_I2C_Write(adress) ' Go to adresa Soft_I2C_Start() ' Issue repeated start signal Soft_I2C_Write(cnfgwr) ' Address for reading R/W=1 result = Soft_I2C_Read(0) ' Read with NAK Soft_I2C_Stop() ' Stop end sub sub procedure I2CW(dim adress, value as byte) ' Write value in TRC Soft_I2C_Start() ' Issue start signal Soft_I2C_Write(cnfgww) ' Address Soft_I2C_Write(adress) ' Go to adresa Soft_I2C_Write(value) ' Write valoare Soft_I2C_Stop() ' Stop end sub sub procedure read_RTC() ' Read some data from RTC btmp=0x00 btmp=I2CR(btmp) 'sec s0 = btmp Mod 16 s1 = btmp / 16 btmp=0x01 btmp=I2CR(btmp) 'min m0 = btmp Mod 16 m1 = btmp / 16 btmp=0x02 btmp=I2CR(btmp) 'hour h0 = btmp Mod 16 h1 = btmp / 16 btmp=0x04 btmp=I2CR(btmp) 'day d0 = btmp Mod 16 d1 = btmp / 16 btmp=0x05 btmp=I2CR(btmp) 'mounth mo0 = btmp Mod 16 mo1 = btmp / 16 btmp=0x06 btmp=I2CR(btmp) 'year y0 = btmp Mod 16 y1 = btmp / 16 btmp=0x08 btmp=I2CR(btmp) 'almin am0 = btmp Mod 16 am1 = btmp / 16 btmp=0x09 btmp=I2CR(btmp) 'alhour ah0 = btmp Mod 16 ah1 = btmp / 16 btmp=0x11 btmp=I2CR(btmp) 'temp th0 = btmp Mod 10 th1 = btmp / 10 btmp=0x0B bright=I2CR(btmp) ' brightness br0 = bright Mod 16 br1 = bright / 16 btmp=0x0C al=I2CR(btmp) ' set alarm On/Off btmp=0x0F btmp=I2CR(btmp) ' flag alarm flgal=btmp.0 btmp=0x0D btmp=I2CR(btmp) ' Temperature On/Off grc=btmp end sub sub procedure maxCMD (dim address, value as byte) ' Send command to MAX7219 CS = 0 for i = 0 to 3 SPI_Write(address) '// Send address. SPI_Write(value) '// Send the value. next i CS = 1 end sub sub procedure max7219_init() ' Initialize MAX7219 maxCMD(MAX7219_TEST, 0x01) ' Test mode maxCMD(MAX7219_TEST, 0x00) ' Finish test mode maxCMD(MAX7219_DECODE_MODE, 0x00) ' Disable BCD mode maxCMD(MAX7219_BRIGHTNESS, bright) ' Use lowest intensity maxCMD(MAX7219_SCAN_LIMIT, 0x0f) ' Scan all digits maxCMD(MAX7219_SHUTDOWN, 0x01) ' Turn on chip end sub 'Prepare hour data sub procedure prepare_to_show_hour(dim m, s_, z_, u, dp1, al1 as byte) for i = 0 to 7 ma[i] = alfabet[m] [i] sa[i] = alfabet[s_] [i] za[i] = alfabet[z_] [i] uua[i] = alfabet[u] [i] next i for i = 0 to 7 utmp[i]=uua[i] next i for i = 0 to 7 utmp[i].7 =za[i].0 next i for i = 0 to 7 ztmp[i]=za[i]>>1 next i for i = 0 to 7 ztmp[i].6 = alfabet[10 + dp1] [i]. 0 ztmp[i].7 = alfabet[10 + dp1] [i]. 1 next i for i = 0 to 7 stmp[i]=sa[i]<<1 next i for i = 0 to 7 mtmp[i]=ma[i] next i mtmp[0].7=al1 for i = 0 to 7 h_dsp[i] = utmp[i] h_dsp[i+8] = ztmp[i] h_dsp[i+16] = stmp[i] h_dsp[i+24] = mtmp[i] next i end sub 'Prepare Temperature data sub procedure prepare_to_show_temp(dim z_, u as byte) for i = 0 to 7 za[i] = alfabet[z_] [i] uua[i] = alfabet[u] [i] next i for i = 0 to 7 mtmp[i] = za[i] >>1 next i for i = 0 to 7 stmp[i]=uua[i] next i for i = 0 to 7 stmp[i].7 =za[i].5 next i for i = 0 to 7 ztmp[i] = alfabet[13] [i] next i for i = 0 to 7 utmp[i] = alfabet[12] [i] <<1 next i for i = 0 to 7 th_dsp[i] = utmp[i] th_dsp[i+8] = ztmp[i] th_dsp[i+16] = stmp[i] th_dsp[i+24] = mtmp[i] next i end sub sub procedure temp2hour 'Scroll from temperature to hour for i = 0 to 7 th_dsp[i+24] = th_dsp[i+24] << 1 th_dsp[i+24].0 = th_dsp[i+16].7 th_dsp[i+16] = th_dsp[i+16] << 1 th_dsp[i+16].0 = th_dsp[i+8].7 th_dsp[i+8] = th_dsp[i+8] << 1 th_dsp[i+8].0 = th_dsp[i].7 th_dsp[i] = th_dsp[i] << 1 th_dsp[i].0 = h_dsp[24+i].7 h_dsp[i+24] = h_dsp[i+24] << 1 h_dsp[i+24].0 = h_dsp[i+16].7 h_dsp[i+16] = h_dsp[i+16] << 1 h_dsp[i+16].0 = h_dsp[i+8].7 h_dsp[i+8] = h_dsp[i+8] << 1 h_dsp[i+8].0 = h_dsp[i].7 h_dsp[i] = h_dsp[i] << 1 next i for i = 0 to 31 dsp[i] = th_dsp[i] next i end sub sub procedure hour2temp 'Scrool from hour to temperature for i = 0 to 7 h_dsp[i+24] = h_dsp[i+24] << 1 h_dsp[i+24].0 = h_dsp[i+16].7 h_dsp[i+16] = h_dsp[i+16] << 1 h_dsp[i+16].0 = h_dsp[i+8].7 h_dsp[i+8] = h_dsp[i+8] << 1 h_dsp[i+8].0 = h_dsp[i].7 h_dsp[i] = h_dsp[i] << 1 h_dsp[i].0 = th_dsp[24+i].7 th_dsp[i+24] = th_dsp[i+24] << 1 th_dsp[i+24].0 = th_dsp[i+16].7 th_dsp[i+16] = th_dsp[i+16] << 1 th_dsp[i+16].0 = th_dsp[i+8].7 th_dsp[i+8] = th_dsp[i+8] << 1 th_dsp[i+8].0 = th_dsp[i].7 th_dsp[i] = th_dsp[i] << 1 next i for i = 0 to 31 dsp[i] = h_dsp[i] next i end sub sub procedure up_down() 'Procedure for Button Up or Button Down if x0 = 1 then if btset = 6 then I2CW(btmod, 0) else btvar = I2CR(btmod) btvar = bcd2dec(btvar) if btvar = mnbt[btset] Then btvar = mxbt[btset] else btvar = btvar - 1 end if I2CW(btmod, dec2bcd(btvar)) end if x0 = 0 end if if x1 = 1 then if btset = 6 then I2CW(btmod, 0) else btvar = I2CR(btmod) btvar = bcd2dec(btvar) if btvar = mxbt[btset] Then btvar = mnbt[btset] else btvar = btvar + 1 end if I2CW(btmod, dec2bcd(btvar)) end if x1 = 0 end if end sub sub procedure prepare_2_show_data ' Prepare data for send to MAX7219 for i = 0 to 31 dsp[i] = h_dsp[i] next i end sub sub procedure send_2_display() ' Send data to MAX7219 for i = 0 to 7 CS = 0 ' Begin transfer. SPI_Write(i+1) ' Send address. SPI_Write(dsp[i+24]) ' Send the value. SPI_Write(i+1) ' Send address. SPI_Write(dsp[i+16]) ' Send the value. SPI_Write(i+1) ' Send address. SPI_Write(dsp[i+8]) ' Send the value. SPI_Write(i+1) ' Send address. SPI_Write(dsp[i]) ' Send the value. CS = 1 ' Finish transfer. next i end sub sub procedure show_data() ' Show received data prepare_2_show_data send_2_display() end sub sub procedure alarm ' Buzz if PORTC1 = 1 PORTB.1 =flgal and al.0 and PORTA.2 end sub sub procedure init_main() OSCCON = %11111111 ' MCU clock at 16 MHz ANSELA = %00000000 ' All I/O pins of the PORTA are configured as digital ANSELB = %00000000 ' All I/O pins of the PORTC are configured as digital CM1CON0 = %00000000 ' Disbale comparator CM2CON0 = %00000000 ' Disbale comparator TRISA = %11111111 ' PORTA All Inputs TRISB = %00000000 ' PORTC All Outputs APFCON0.SDO1SEL = 0 APFCON0.SS1SEL = 0 INTCON.GIE = 1 ' Enables all unmasked interrupts INTCON.PEIE = 0 ' Disables all peripheral interrupts INTCON.T0IE = 1 ' Enables the TMR0 interrupt INTCON.INTE = 1 ' Enables the RA2/INT external interrupt INTCON.IOCIE = 0 ' Disables the PORTA change interrupt INTCON.T0IF = 0 ' TMR0 register did not overflow INTCON.INTF = 0 ' The RA2/INT external interrupt did not occur INTCON.IOCIF = 0 ' None of the PORTA <5:0> pins have changed state OPTION_REG.WUE = 0 ' PORTA pull-ups are enabled by individual port latch values OPTION_REG.INTEDG = 0 ' Interrupt on rising/falling edge of RA2/INT pin OPTION_REG.T0CS = 0 ' set Timer0 clock source to internal OPTION_REG.T0SE = 1 ' Increment on high-to-low transition on RA2/T0CKI pin OPTION_REG.PSA = 0 ' asign prescaler to Timer 0 OPTION_REG.PS2 = 1 ' asign prescaler value OPTION_REG.PS1 = 1 ' asign prescaler value OPTION_REG.PS0 = 1 ' asign prescaler value WPUA = %11111111 ' Pull-ups PORTA to be enabled SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH) Soft_I2C_Init() ' Initialize I2C module SPI1_Init() ' Initialize SPI module btmp=0xB ' Set brtightness adress bright=I2CR(btmp) ' Read brtightness value grc=0 ' Read Temp_On/Off value btmp=0xC ' Set alarm on/off adress al=I2CR(btmp) ' Read alarm on/off value max7219_init() ' Initialize MAX7219 module PORTB.1 = 0 ' Do not start alarm on start_up I2CW(0xA,%10000000) ' Alarm when hours, minutes, and seconds match I2CW(0x0E,0) ' Square wave is output on the INT/SQW pin TRISB.1 = 0 ' Because SPI1_Init make PORTB1 as input str = 0 j = 0 y = 0 k = 0 x = 0 x0 = 0 x1 = 0 x5 = 0 flgint = 0 pflgint = 0 flgal = 0 dp = 0 btset = 0 CS=1 end sub sub procedure Interrupt() iv 0x0004 ics ICS_AUTO if INTCON.INTF = 1 then flgint = not flgint OPTION_REG.INTEDG = not OPTION_REG.INTEDG dp.0 = not dp.0 k = k + 1 if k = 23 then k = 0 end if INTCON.INTF = 0 End if if INTCON.T0IF = 1 then TMR0 = 61 if flgal and al.0 and portb.0 then end if y = y + 1 if y = 20 then flsh = not flsh y = 0 end if ' buton mod if Button(PORTA, 4, 1, 1) then k4 = 255 end if if k4 and Button(PORTA, 4, 1, 0) then btset = btset + 1 if btset= 11 then btset= 0 end if btmod = stadrs[btset] k4 = 0 end if ' Button Up if btset <> 0 then if Button(PORTA, 0, 1, 1) then k0 = 255 end if if k0 and Button(PORTA, 0, 1, 0) then k0 = 0 x0 = 1 end if end if ' Button Down if btset <> 0 then if Button(PORTA, 1, 1, 1) then k1 = 255 end if if k1 and Button(PORTA, 1, 1, 0) then k1 = 0 x1 = 1 end if end if ' Button Al On/Off if Button(PORTA, 2, 1, 1) then k5 = 255 end if if k5 and Button(PORTA, 2, 1, 0) then x5 = 1 k5 = 0 end if INTCON.T0IF = 0 End if end sub main: ' Main program delay_ms(100) init_main() while TRUE select case btset case 0 ' show alt hour & temperature if flgint <> pflgint then pflgint = flgint read_RTC() prepare_to_show_hour(h1, h0, m1, m0, dp, al ) prepare_to_show_temp(th1, th0) if grc = 1 then if k<=16 then if k=16 then dp = 1 prepare_to_show_hour(h1, h0, m1, m0, dp, al ) for yy = 0 to 31 hour2temp send_2_display() delay_ms(30) alarm() next yy else prepare_2_show_data send_2_display() alarm() end if else if k=22 then dp = 1 prepare_to_show_hour(h1, h0, m1, m0, dp, al ) for yy = 0 to 31 temp2hour send_2_display() delay_ms(30) alarm() next yy else prepare_to_show_temp(th1, th0) for i = 0 to 31 dsp[i] = th_dsp[i] next i send_2_display() alarm() end if end if else show_data alarm() end if end if case 1 read_RTC() if flsh = 0 then h1 = 10 h0 = 10 end if prepare_to_show_hour(h1, h0, m1, m0, 1, 0 ) show_data() up_down() case 2 read_RTC() if flsh = 0 then m1 = 10 m0 = 10 end if prepare_to_show_hour(h1, h0, m1, m0, 1, 0 ) show_data() up_down() case 3 read_RTC() if flsh = 0 then d1 = 10 d0 = 10 end if prepare_to_show_hour(d1, d0, mo1, mo0, 0, 0 ) show_data() up_down() case 4 read_RTC() if flsh = 0 then mo1 = 10 mo0 = 10 end if prepare_to_show_hour(d1, d0, mo1, mo0, 0, 0 ) show_data() up_down() case 5 read_RTC() if flsh = 0 then y1 = 10 y0 = 10 end if prepare_to_show_hour(2, 0, y1, y0, 0, 0 ) show_data() up_down() case 6 read_RTC() if flsh = 0 then s1 = 10 s0 = 10 end if prepare_to_show_hour(10, 10, s1, s0, 1, 0 ) show_data() up_down() case 7 read_RTC() if flsh = 0 then ah1 = 10 ah0 = 10 end if prepare_to_show_hour(ah1, ah0, am1, am0, 1, 1 ) show_data() up_down() case 8 read_RTC() if flsh = 0 then am1 = 10 am0 = 10 end if prepare_to_show_hour(ah1, ah0, am1, am0, 1, 1 ) show_data() up_down() case 9 read_RTC() if flsh = 0 then br1 = 10 br0 = 10 end if prepare_to_show_hour(14, 15, br1, br0, 1, 0 ) show_data() up_down() read_RTC() maxCMD(MAX7219_BRIGHTNESS, bcd2dec(bright)) case 10 read_RTC() if flsh = 0 then grc = 10 end if prepare_to_show_hour(13, 12, 0, grc, 1, 0 ) show_data() up_down() end select if x5 = 1 then x5 = 0 if al <> 0 then al = 0 else al = 1 end if while not k5.0 prepare_to_show_hour(ah1, ah0, am1, am0, 1, 1 ) show_data() wend I2CW(0xc,dec2bcd(al)) ' Alarm On/Off I2CW(0xf,dec2bcd(0x0)) ' Clear alarm flag end if alarm() wend end. @nel65 hex pt 1825 Varianta cu DS 18B20 Ceas_MAX7219_PIC1825.hex
  4. pentru cel cu 1827 nu garantez ca merge fizic, fiindca nu l-am relizat.
  5. @fratello incearca codul de mai jos. Mie mi-a compilat program Ceas_MAX7219_PIC1827 ' Declarations section Const cnfgww As Byte = %11010000 'Adress for write DS3231 Const cnfgwr As Byte = %11010001 'Adress for read DS3231 const MAX7219_TEST as byte =0x0F const MAX7219_BRIGHTNESS as byte = 0x0A const MAX7219_SCAN_LIMIT as byte = 0x0B const MAX7219_DECODE_MODE as byte = 0x09 const MAX7219_SHUTDOWN as byte = 0x0C const mxbt As Byte[11] =(0, 23, 59, 31, 12, 99, 59, 23, 59, 15, 1) ' max value const mnbt As Byte[11] =(0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0) ' min value const stadrs As Byte[11] =(0, 0x02, 0x01, 0x04, 0x05, 0x06, 0x00, 0x09, 0x08, 0x0B, 0x0D) ' Adress data RTC const alfabet as byte [16] [8]= (( 30, 63, 51, 51, 51, 51, 63, 30), '0 ( 6, 14, 30, 6, 6, 6, 6, 15), '1 ( 30, 63, 35, 6, 12, 24, 63, 63), '2 ( 30, 63, 35, 14, 14, 35, 63, 30), '3 ( 6, 14, 30, 54, 54, 63, 6, 15), '4 ( 62, 63, 48, 62, 51, 3, 63, 30), '5 ( 30, 63, 48, 62, 51, 51, 63, 30), '6 ( 63, 63, 3, 6, 12, 12, 12, 12), '7 ( 30, 63, 51, 30, 51, 51, 63, 30), '8 ( 30, 63, 51, 51, 31, 3, 63, 30), '9 ( 0, 0, 0, 0, 0, 0, 0, 0), 'blank ( 0, 3, 3, 0, 0, 3, 3, 0), 'dp (120, 124, 68, 64, 64, 68, 124, 120), 'C ( 56, 109, 109, 109, 57, 1, 1, 0), '` ( 62, 63, 51, 62, 51, 51, 63, 62), 'B ( 0, 0, 27, 31, 28, 24, 24, 24)) 'r Dim CS as sbit at RB3_bit 'Chip Select pin for MAX7219 CS_Direction as sbit at TRISB3_bit Dim Soft_I2C_Sda as sbit at RB6_bit 'SDA pin for DS3231 Dim Soft_I2C_Scl as sbit at RB7_bit 'SCL pin for DS3231 Dim Soft_I2C_Sda_Direction as sbit at TRISB6_bit Dim Soft_I2C_Scl_Direction as sbit at TRISB7_bit Dim i,j, x, y, yy, bright, m, s_, z_, u, dp, str as byte Dim k, k0, k1, k4, k5, al as byte Dim flgal, flsh, x0, x1, x5, flgint, pflgint as bit Dim ma, sa, za, uua, utmp, ztmp, stmp, ltmp, rtmp, mtmp as byte[8] Dim dsp, th_dsp, h_dsp as byte[32] Dim s0, s1, m0, m1, h0, h1, ah0, ah1, am0, am1 As Byte Dim d0, d1, mo0, mo1, y0, y1, th0, th1, br1, br0 As Byte Dim btset, btmod, btvar, btmp, grc As Byte sub function I2CR(dim byref adress as byte) as byte ' Read value from RTC Soft_I2C_Start() ' Issue start signal Soft_I2C_Write(cnfgww) ' Address DS3221 datasheet Soft_I2C_Write(adress) ' Go to adresa Soft_I2C_Start() ' Issue repeated start signal Soft_I2C_Write(cnfgwr) ' Address for reading R/W=1 result = Soft_I2C_Read(0) ' Read with NAK Soft_I2C_Stop() ' Stop end sub sub procedure I2CW(dim adress, value as byte) ' Write value in TRC Soft_I2C_Start() ' Issue start signal Soft_I2C_Write(cnfgww) ' Address Soft_I2C_Write(adress) ' Go to adresa Soft_I2C_Write(value) ' Write valoare Soft_I2C_Stop() ' Stop end sub sub procedure read_RTC() ' Read some data from RTC btmp=0x00 btmp=I2CR(btmp) 'sec s0 = btmp Mod 16 s1 = btmp / 16 btmp=0x01 btmp=I2CR(btmp) 'min m0 = btmp Mod 16 m1 = btmp / 16 btmp=0x02 btmp=I2CR(btmp) 'hour h0 = btmp Mod 16 h1 = btmp / 16 btmp=0x04 btmp=I2CR(btmp) 'day d0 = btmp Mod 16 d1 = btmp / 16 btmp=0x05 btmp=I2CR(btmp) 'mounth mo0 = btmp Mod 16 mo1 = btmp / 16 btmp=0x06 btmp=I2CR(btmp) 'year y0 = btmp Mod 16 y1 = btmp / 16 btmp=0x08 btmp=I2CR(btmp) 'almin am0 = btmp Mod 16 am1 = btmp / 16 btmp=0x09 btmp=I2CR(btmp) 'alhour ah0 = btmp Mod 16 ah1 = btmp / 16 btmp=0x11 btmp=I2CR(btmp) 'temp th0 = btmp Mod 10 th1 = btmp / 10 btmp=0x0B bright=I2CR(btmp) ' brightness br0 = bright Mod 16 br1 = bright / 16 btmp=0x0C al=I2CR(btmp) ' set alarm On/Off btmp=0x0F btmp=I2CR(btmp) ' flag alarm flgal=btmp.0 btmp=0x0D btmp=I2CR(btmp) ' Temperature On/Off grc=btmp end sub sub procedure maxCMD (dim address, value as byte) ' Send command to MAX7219 CS = 0 for i = 0 to 3 SPI_Write(address) '// Send address. SPI_Write(value) '// Send the value. next i CS = 1 end sub sub procedure max7219_init() ' Initialize MAX7219 maxCMD(MAX7219_TEST, 0x01) ' Test mode maxCMD(MAX7219_TEST, 0x00) ' Finish test mode maxCMD(MAX7219_DECODE_MODE, 0x00) ' Disable BCD mode maxCMD(MAX7219_BRIGHTNESS, bright) ' Use lowest intensity maxCMD(MAX7219_SCAN_LIMIT, 0x0f) ' Scan all digits maxCMD(MAX7219_SHUTDOWN, 0x01) ' Turn on chip end sub 'Prepare hour data sub procedure prepare_to_show_hour(dim m, s_, z_, u, dp1, al1 as byte) for i = 0 to 7 ma[i] = alfabet[m] [i] sa[i] = alfabet[s_] [i] za[i] = alfabet[z_] [i] uua[i] = alfabet[u] [i] next i for i = 0 to 7 utmp[i]=uua[i] next i for i = 0 to 7 utmp[i].7 =za[i].0 next i for i = 0 to 7 ztmp[i]=za[i]>>1 next i for i = 0 to 7 ztmp[i].6 = alfabet[10 + dp1] [i]. 0 ztmp[i].7 = alfabet[10 + dp1] [i]. 1 next i for i = 0 to 7 stmp[i]=sa[i]<<1 next i for i = 0 to 7 mtmp[i]=ma[i] next i mtmp[0].7=al1 for i = 0 to 7 h_dsp[i] = utmp[i] h_dsp[i+8] = ztmp[i] h_dsp[i+16] = stmp[i] h_dsp[i+24] = mtmp[i] next i end sub 'Prepare Temperature data sub procedure prepare_to_show_temp(dim z_, u as byte) for i = 0 to 7 za[i] = alfabet[z_] [i] uua[i] = alfabet[u] [i] next i for i = 0 to 7 mtmp[i] = za[i] >>1 next i for i = 0 to 7 stmp[i]=uua[i] next i for i = 0 to 7 stmp[i].7 =za[i].5 next i for i = 0 to 7 ztmp[i] = alfabet[13] [i] next i for i = 0 to 7 utmp[i] = alfabet[12] [i] <<1 next i for i = 0 to 7 th_dsp[i] = utmp[i] th_dsp[i+8] = ztmp[i] th_dsp[i+16] = stmp[i] th_dsp[i+24] = mtmp[i] next i end sub sub procedure temp2hour 'Scroll from temperature to hour for i = 0 to 7 th_dsp[i+24] = th_dsp[i+24] << 1 th_dsp[i+24].0 = th_dsp[i+16].7 th_dsp[i+16] = th_dsp[i+16] << 1 th_dsp[i+16].0 = th_dsp[i+8].7 th_dsp[i+8] = th_dsp[i+8] << 1 th_dsp[i+8].0 = th_dsp[i].7 th_dsp[i] = th_dsp[i] << 1 th_dsp[i].0 = h_dsp[24+i].7 h_dsp[i+24] = h_dsp[i+24] << 1 h_dsp[i+24].0 = h_dsp[i+16].7 h_dsp[i+16] = h_dsp[i+16] << 1 h_dsp[i+16].0 = h_dsp[i+8].7 h_dsp[i+8] = h_dsp[i+8] << 1 h_dsp[i+8].0 = h_dsp[i].7 h_dsp[i] = h_dsp[i] << 1 next i for i = 0 to 31 dsp[i] = th_dsp[i] next i end sub sub procedure hour2temp 'Scrool from hour to temperature for i = 0 to 7 h_dsp[i+24] = h_dsp[i+24] << 1 h_dsp[i+24].0 = h_dsp[i+16].7 h_dsp[i+16] = h_dsp[i+16] << 1 h_dsp[i+16].0 = h_dsp[i+8].7 h_dsp[i+8] = h_dsp[i+8] << 1 h_dsp[i+8].0 = h_dsp[i].7 h_dsp[i] = h_dsp[i] << 1 h_dsp[i].0 = th_dsp[24+i].7 th_dsp[i+24] = th_dsp[i+24] << 1 th_dsp[i+24].0 = th_dsp[i+16].7 th_dsp[i+16] = th_dsp[i+16] << 1 th_dsp[i+16].0 = th_dsp[i+8].7 th_dsp[i+8] = th_dsp[i+8] << 1 th_dsp[i+8].0 = th_dsp[i].7 th_dsp[i] = th_dsp[i] << 1 next i for i = 0 to 31 dsp[i] = h_dsp[i] next i end sub sub procedure up_down() 'Procedure for Button Up or Button Down if x0 = 1 then if btset = 6 then I2CW(btmod, 0) else btvar = I2CR(btmod) btvar = bcd2dec(btvar) if btvar = mnbt[btset] Then btvar = mxbt[btset] else btvar = btvar - 1 end if I2CW(btmod, dec2bcd(btvar)) end if x0 = 0 end if if x1 = 1 then if btset = 6 then I2CW(btmod, 0) else btvar = I2CR(btmod) btvar = bcd2dec(btvar) if btvar = mxbt[btset] Then btvar = mnbt[btset] else btvar = btvar + 1 end if I2CW(btmod, dec2bcd(btvar)) end if x1 = 0 end if end sub sub procedure prepare_2_show_data ' Prepare data for send to MAX7219 for i = 0 to 31 dsp[i] = h_dsp[i] next i end sub sub procedure send_2_display() ' Send data to MAX7219 for i = 0 to 7 CS = 0 ' Begin transfer. SPI_Write(i+1) ' Send address. SPI_Write(dsp[i+24]) ' Send the value. SPI_Write(i+1) ' Send address. SPI_Write(dsp[i+16]) ' Send the value. SPI_Write(i+1) ' Send address. SPI_Write(dsp[i+8]) ' Send the value. SPI_Write(i+1) ' Send address. SPI_Write(dsp[i]) ' Send the value. CS = 1 ' Finish transfer. next i end sub sub procedure show_data() ' Show received data prepare_2_show_data send_2_display() end sub sub procedure alarm ' Buzz if PORTC1 = 1 PORTB.1 =flgal and al.0 and PORTA.2 end sub sub procedure init_main() OSCCON = %11111111 ' MCU clock at 16 MHz ANSELA = %00000000 ' All I/O pins of the PORTA are configured as digital ANSELB = %00000000 ' All I/O pins of the PORTC are configured as digital CM1CON0 = %00000000 ' Disbale comparator CM2CON0 = %00000000 ' Disbale comparator TRISA = %11111111 ' PORTA All Inputs TRISB = %00000000 ' PORTC All Outputs APFCON0.SDO1SEL = 0 APFCON0.SS1SEL = 0 INTCON.GIE = 1 ' Enables all unmasked interrupts INTCON.PEIE = 0 ' Disables all peripheral interrupts INTCON.T0IE = 1 ' Enables the TMR0 interrupt INTCON.INTE = 1 ' Enables the RA2/INT external interrupt INTCON.IOCIE = 0 ' Disables the PORTA change interrupt INTCON.T0IF = 0 ' TMR0 register did not overflow INTCON.INTF = 0 ' The RA2/INT external interrupt did not occur INTCON.IOCIF = 0 ' None of the PORTA <5:0> pins have changed state OPTION_REG.WUE = 0 ' PORTA pull-ups are enabled by individual port latch values OPTION_REG.INTEDG = 0 ' Interrupt on rising/falling edge of RA2/INT pin OPTION_REG.T0CS = 0 ' set Timer0 clock source to internal OPTION_REG.T0SE = 1 ' Increment on high-to-low transition on RA2/T0CKI pin OPTION_REG.PSA = 0 ' asign prescaler to Timer 0 OPTION_REG.PS2 = 1 ' asign prescaler value OPTION_REG.PS1 = 1 ' asign prescaler value OPTION_REG.PS0 = 1 ' asign prescaler value WPUA = %00111111 ' Pull-ups PORTA to be enabled SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH) Soft_I2C_Init() ' Initialize I2C module SPI1_Init() ' Initialize SPI module btmp=0xB ' Set brtightness adress bright=I2CR(btmp) ' Read brtightness value grc=0 ' Read Temp_On/Off value btmp=0xC ' Set alarm on/off adress al=I2CR(btmp) ' Read alarm on/off value max7219_init() ' Initialize MAX7219 module PORTB.1 = 0 ' Do not start alarm on start_up I2CW(0xA,%10000000) ' Alarm when hours, minutes, and seconds match I2CW(0x0E,0) ' Square wave is output on the INT/SQW pin TRISB.1 = 0 ' Because SPI1_Init make PORTC1 as input str = 0 j = 0 y = 0 k = 0 x = 0 x0 = 0 x1 = 0 x5 = 0 flgint = 0 pflgint = 0 flgal = 0 dp = 0 btset = 0 CS=1 end sub sub procedure Interrupt() iv 0x0004 ics ICS_AUTO if INTCON.INTF = 1 then flgint = not flgint OPTION_REG.INTEDG = not OPTION_REG.INTEDG dp.0 = not dp.0 k = k + 1 if k = 23 then k = 0 end if INTCON.INTF = 0 End if if INTCON.T0IF = 1 then TMR0 = 61 if flgal and al.0 and porta.2 then end if y = y + 1 if y = 20 then flsh = not flsh y = 0 end if ' buton mod if Button(PORTA, 4, 1, 1) then k4 = 255 end if if k4 and Button(PORTA, 4, 1, 0) then btset = btset + 1 if btset= 11 then btset= 0 end if btmod = stadrs[btset] k4 = 0 end if ' Button Up if btset <> 0 then if Button(PORTA, 0, 1, 1) then k0 = 255 end if if k0 and Button(PORTA, 0, 1, 0) then k0 = 0 x0 = 1 end if end if ' Button Down if btset <> 0 then if Button(PORTA, 1, 1, 1) then k1 = 255 end if if k1 and Button(PORTA, 1, 1, 0) then k1 = 0 x1 = 1 end if end if ' Button Al On/Off if Button(PORTA, 5, 1, 1) then k5 = 255 end if if k5 and Button(PORTA, 5, 1, 0) then x5 = 1 k5 = 0 end if INTCON.T0IF = 0 End if end sub main: ' Main program delay_ms(100) init_main() while TRUE select case btset case 0 ' show alt hour & temperature if flgint <> pflgint then pflgint = flgint read_RTC() prepare_to_show_hour(h1, h0, m1, m0, dp, al ) prepare_to_show_temp(th1, th0) if grc = 1 then if k<=16 then if k=16 then dp = 1 prepare_to_show_hour(h1, h0, m1, m0, dp, al ) for yy = 0 to 31 hour2temp send_2_display() delay_ms(30) alarm() next yy else prepare_2_show_data send_2_display() alarm() end if else if k=22 then dp = 1 prepare_to_show_hour(h1, h0, m1, m0, dp, al ) for yy = 0 to 31 temp2hour send_2_display() delay_ms(30) alarm() next yy else prepare_to_show_temp(th1, th0) for i = 0 to 31 dsp[i] = th_dsp[i] next i send_2_display() alarm() end if end if else show_data alarm() end if end if case 1 read_RTC() if flsh = 0 then h1 = 10 h0 = 10 end if prepare_to_show_hour(h1, h0, m1, m0, 1, 0 ) show_data() up_down() case 2 read_RTC() if flsh = 0 then m1 = 10 m0 = 10 end if prepare_to_show_hour(h1, h0, m1, m0, 1, 0 ) show_data() up_down() case 3 read_RTC() if flsh = 0 then d1 = 10 d0 = 10 end if prepare_to_show_hour(d1, d0, mo1, mo0, 0, 0 ) show_data() up_down() case 4 read_RTC() if flsh = 0 then mo1 = 10 mo0 = 10 end if prepare_to_show_hour(d1, d0, mo1, mo0, 0, 0 ) show_data() up_down() case 5 read_RTC() if flsh = 0 then y1 = 10 y0 = 10 end if prepare_to_show_hour(2, 0, y1, y0, 0, 0 ) show_data() up_down() case 6 read_RTC() if flsh = 0 then s1 = 10 s0 = 10 end if prepare_to_show_hour(10, 10, s1, s0, 1, 0 ) show_data() up_down() case 7 read_RTC() if flsh = 0 then ah1 = 10 ah0 = 10 end if prepare_to_show_hour(ah1, ah0, am1, am0, 1, 1 ) show_data() up_down() case 8 read_RTC() if flsh = 0 then am1 = 10 am0 = 10 end if prepare_to_show_hour(ah1, ah0, am1, am0, 1, 1 ) show_data() up_down() case 9 read_RTC() if flsh = 0 then br1 = 10 br0 = 10 end if prepare_to_show_hour(14, 15, br1, br0, 1, 0 ) show_data() up_down() read_RTC() maxCMD(MAX7219_BRIGHTNESS, bcd2dec(bright)) case 10 read_RTC() if flsh = 0 then grc = 10 end if prepare_to_show_hour(13, 12, 0, grc, 1, 0 ) show_data() up_down() end select if x5 = 1 then x5 = 0 if al <> 0 then al = 0 else al = 1 end if while not k5.0 prepare_to_show_hour(ah1, ah0, am1, am0, 1, 1 ) show_data() wend I2CW(0xc,dec2bcd(al)) ' Alarm On/Off I2CW(0xf,dec2bcd(0x0)) ' Clear alarm flag end if alarm() wend end.
  6. Tu folosesti varianta demo care este limitata la 2k ROM
  7. Introdu si prima linie, aia cu program .... Sau ia cu copy paste tot ceea ce e scris in cod
  8. Salut @fratello Ma bucur ca-ti place proiectul meu! Programul prezentat in primul post a fost scris in MikroBasic PRO for PIC de la Mikroe, eu detin var 6.4.0. Intre timp am realizat o alta varianta (pe care o recomand a fi realizata), deoarece asamblat in carcasa, matricile incalzesc interiorul acesteia, iar temperatura citita din RTC este mai mare decat a mediului ambiant. Solutia adoptata a fost ca temperatura sa o citesc dintr-un DS18B20 montat in exteriorul carcasei, astfel temperatura afisata este cea a mediului ambiant. O alta imbunatatire fata de varianta anterioara este afisarea corecta a temperaturilor negative. Deoarece a crescut marimea programului a trebuit sa folosesc alt PIC si anume fratele mai mare a celui initial - PIC 16F1825. Schema a devenit urmatoarea (rezistenta de 2M2 si conectorul X1 nu se vor monta, acestea fiind prevazute pentru o dezvoltare ulterioara a proiectului care sa seteze intensitatea luminoasa a afisajului in fct de lumina ambientala): Programul este mai jos, fontul il modifici schimband itemii din variabila alfabet. Pentru usurinta iti recomand sa-ti faci un program in excel, unde setezi coloanele egale cu randurile, introduci 1 in celulele "aprinse" si cu o formula iti determini itemii fontului. Programul poate fi transpus foarte usor pentru Arduino (vad ca este foarte la moda acum!) program Ceas_MAX7219_PIC1825 ' Declarations section Const cnfgww As Byte = %11010000 'Adress for write DS3231 Const cnfgwr As Byte = %11010001 'Adress for read DS3231 const TEMP_RESOLUTION as byte = 9 const MAX7219_TEST as byte =0x0F const MAX7219_BRIGHTNESS as byte = 0x0A const MAX7219_SCAN_LIMIT as byte = 0x0B const MAX7219_DECODE_MODE as byte = 0x09 const MAX7219_SHUTDOWN as byte = 0x0C const mxbt As Byte[11] =(0, 23, 59, 31, 12, 99, 59, 23, 59, 15, 1) ' max value const mnbt As Byte[11] =(0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0) ' min value const stadrs As Byte[11] =(0, 0x02, 0x01, 0x04, 0x05, 0x06, 0x00, 0x09, 0x08, 0x0B, 0x0D) ' Adress data RTC const alfabet as byte [17] [8]= (( 30, 63, 51, 51, 51, 51, 63, 30), '0 ( 6, 14, 30, 6, 6, 6, 6, 15), '1 ( 30, 63, 35, 6, 12, 24, 63, 63), '2 ( 30, 63, 35, 14, 14, 35, 63, 30), '3 ( 6, 14, 30, 54, 54, 63, 6, 15), '4 ( 62, 63, 48, 62, 51, 3, 63, 30), '5 ( 30, 63, 48, 62, 51, 51, 63, 30), '6 ( 63, 63, 3, 6, 12, 12, 12, 12), '7 ( 30, 63, 51, 30, 51, 51, 63, 30), '8 ( 30, 63, 51, 51, 31, 3, 63, 30), '9 ( 0, 0, 0, 0, 0, 0, 0, 0), 'blank ( 0, 3, 3, 0, 0, 3, 3, 0), 'dp (120, 124, 68, 64, 64, 68, 124, 120), 'C ( 56, 109, 109, 109, 57, 1, 1, 0), '` ( 62, 63, 51, 62, 51, 51, 63, 62), 'B ( 0, 0, 27, 31, 28, 24, 24, 24), 'r ( 0, 0, 0, 7, 7, 0, 0, 0)) '- Dim CS as sbit at RC3_bit 'Chip Select pin for MAX7219 CS_Direction as sbit at TRISC3_bit Dim Soft_I2C_Sda as sbit at RA0_bit 'SDA pin for DS3231 Dim Soft_I2C_Scl as sbit at RA1_bit 'SCL pin for DS3231 Dim Soft_I2C_Sda_Direction as sbit at TRISA0_bit Dim Soft_I2C_Scl_Direction as sbit at TRISA1_bit Dim i,j, x, y, yy, bright, m, s_, z_, u, dp, str as byte Dim k, k0, k1, k4, k5, al as byte Dim flgal, flsh, x0, x1, x5, flgint, pflgint,tal,tal1 as bit Dim ma, sa, za, uua, utmp, ztmp, stmp, ltmp, rtmp, mtmp as byte[8] Dim dsp, th_dsp, h_dsp as byte[32] Dim s0, s1, m0, m1, h0, h1, ah0, ah1, am0, am1 As Byte Dim d0, d1, mo0, mo1, y0, y1, th0, th1, br1, br0 As Byte Dim btset, btmod, btvar, btmp, grc, ytal, tsgn As Byte dim temp1 as word sub function I2CR(dim byref adress as byte) as byte ' Read value from RTC Soft_I2C_Start() ' Issue start signal Soft_I2C_Write(cnfgww) ' Address DS3231 Soft_I2C_Write(adress) ' Go to adresa Soft_I2C_Start() ' Issue repeated start signal Soft_I2C_Write(cnfgwr) ' Address for reading R/W=1 result = Soft_I2C_Read(0) ' Read with NAK Soft_I2C_Stop() ' Stop end sub sub procedure I2CW(dim adress, value as byte) ' Write value in TRC Soft_I2C_Start() ' Issue start signal Soft_I2C_Write(cnfgww) ' Address Soft_I2C_Write(adress) ' Go to adresa Soft_I2C_Write(value) ' Write valoare Soft_I2C_Stop() ' Stop end sub sub procedure read_RTC() ' Read some data from RTC btmp=0x00 btmp=I2CR(btmp) 'sec s0 = btmp Mod 16 s1 = btmp / 16 btmp=0x01 btmp=I2CR(btmp) 'min m0 = btmp Mod 16 m1 = btmp / 16 btmp=0x02 btmp=I2CR(btmp) 'hour h0 = btmp Mod 16 h1 = btmp / 16 btmp=0x04 btmp=I2CR(btmp) 'day d0 = btmp Mod 16 d1 = btmp / 16 btmp=0x05 btmp=I2CR(btmp) 'mounth mo0 = btmp Mod 16 mo1 = btmp / 16 btmp=0x06 btmp=I2CR(btmp) 'year y0 = btmp Mod 16 y1 = btmp / 16 btmp=0x08 btmp=I2CR(btmp) 'almin am0 = btmp Mod 16 am1 = btmp / 16 btmp=0x09 btmp=I2CR(btmp) 'alhour ah0 = btmp Mod 16 ah1 = btmp / 16 btmp=0x0B bright=I2CR(btmp) ' brightness br0 = bright Mod 16 br1 = bright / 16 btmp=0x0C al=I2CR(btmp) ' set alarm On/Off btmp=0x0F btmp=I2CR(btmp) ' flag alarm flgal=btmp.0 btmp=0x0D btmp=I2CR(btmp) ' Temperature On/Off grc=btmp end sub sub procedure maxCMD (dim address, value as byte) ' Send command to MAX7219 CS = 0 for i = 0 to 3 SPI_Write(address) '// Send address. SPI_Write(value) '// Send the value. next i CS = 1 end sub sub procedure max7219_init() ' Initialize MAX7219 maxCMD(MAX7219_TEST, 0x01) ' Test mode maxCMD(MAX7219_TEST, 0x00) ' Finish test mode maxCMD(MAX7219_DECODE_MODE, 0x00) ' Disable BCD mode maxCMD(MAX7219_BRIGHTNESS, bright) ' Use lowest intensity maxCMD(MAX7219_SCAN_LIMIT, 0x0f) ' Scan all digits maxCMD(MAX7219_SHUTDOWN, 0x01) ' Turn on chip end sub 'Prepare hour data sub procedure prepare_to_show_hour(dim m, s_, z_, u, dp1, al1 as byte) for i = 0 to 7 ma[i] = alfabet[m] [i] sa[i] = alfabet[s_] [i] za[i] = alfabet[z_] [i] uua[i] = alfabet[u] [i] next i for i = 0 to 7 utmp[i]=uua[i] utmp[i].7 =za[i].0 ztmp[i]=za[i]>>1 next i for i = 0 to 7 ztmp[i].6 = alfabet[10 + dp1] [i]. 0 ztmp[i].7 = alfabet[10 + dp1] [i]. 1 stmp[i]=sa[i]<<1 mtmp[i]=ma[i] next i mtmp[0].7=al1.0 for i = 0 to 7 h_dsp[i] = utmp[i] h_dsp[i+8] = ztmp[i] h_dsp[i+16] = stmp[i] h_dsp[i+24] = mtmp[i] next i end sub 'Prepare Temperature data sub procedure prepare_to_show_temp(dim tsgn, z_, u as byte) for i = 0 to 7 ma[i] = alfabet[tsgn] [i] za[i] = alfabet[z_] [i] uua[i] = alfabet[u] [i] next i for i = 0 to 7 utmp[i] = alfabet[12] [i] >>1 utmp[i].6 = alfabet[13] [i].0 ztmp[i] = alfabet[13] [i] >> 2 ztmp[i].6 = uua[i].0 ztmp[i].7 = uua[i].1 stmp[i] = uua [i] >> 2 stmp[i].5 = za[i].0 stmp[i].6 = za[i].1 stmp[i].7 = za[i].2 mtmp[i]=ma[i] << 4 mtmp[i].0 = za[i].3 mtmp[i].1 = za[i].4 mtmp[i].2 = za[i].5 next i for i = 0 to 7 th_dsp[i] = utmp[i] th_dsp[i+8] = ztmp[i] th_dsp[i+16] = stmp[i] th_dsp[i+24] = mtmp[i] next i end sub sub procedure temp2hour 'Scroll from temperature to hour for i = 0 to 7 th_dsp[i+24] = th_dsp[i+24] << 1 th_dsp[i+24].0 = th_dsp[i+16].7 th_dsp[i+16] = th_dsp[i+16] << 1 th_dsp[i+16].0 = th_dsp[i+8].7 th_dsp[i+8] = th_dsp[i+8] << 1 th_dsp[i+8].0 = th_dsp[i].7 th_dsp[i] = th_dsp[i] << 1 th_dsp[i].0 = h_dsp[24+i].7 h_dsp[i+24] = h_dsp[i+24] << 1 h_dsp[i+24].0 = h_dsp[i+16].7 h_dsp[i+16] = h_dsp[i+16] << 1 h_dsp[i+16].0 = h_dsp[i+8].7 h_dsp[i+8] = h_dsp[i+8] << 1 h_dsp[i+8].0 = h_dsp[i].7 h_dsp[i] = h_dsp[i] << 1 next i for i = 0 to 31 dsp[i] = th_dsp[i] next i end sub sub procedure hour2temp 'Scrool from hour to temperature for i = 0 to 7 h_dsp[i+24] = h_dsp[i+24] << 1 h_dsp[i+24].0 = h_dsp[i+16].7 h_dsp[i+16] = h_dsp[i+16] << 1 h_dsp[i+16].0 = h_dsp[i+8].7 h_dsp[i+8] = h_dsp[i+8] << 1 h_dsp[i+8].0 = h_dsp[i].7 h_dsp[i] = h_dsp[i] << 1 h_dsp[i].0 = th_dsp[24+i].7 th_dsp[i+24] = th_dsp[i+24] << 1 th_dsp[i+24].0 = th_dsp[i+16].7 th_dsp[i+16] = th_dsp[i+16] << 1 th_dsp[i+16].0 = th_dsp[i+8].7 th_dsp[i+8] = th_dsp[i+8] << 1 th_dsp[i+8].0 = th_dsp[i].7 th_dsp[i] = th_dsp[i] << 1 next i for i = 0 to 31 dsp[i] = h_dsp[i] next i end sub sub procedure up_down() 'Procedure for Button Up or Button Down if x0 = 1 then if btset = 6 then I2CW(btmod, 0) else btvar = I2CR(btmod) btvar = bcd2dec(btvar) if btvar = mnbt[btset] Then btvar = mxbt[btset] else btvar = btvar - 1 end if I2CW(btmod, dec2bcd(btvar)) end if x0 = 0 end if if x1 = 1 then if btset = 6 then I2CW(btmod, 0) else btvar = I2CR(btmod) btvar = bcd2dec(btvar) if btvar = mxbt[btset] Then btvar = mnbt[btset] else btvar = btvar + 1 end if I2CW(btmod, dec2bcd(btvar)) end if x1 = 0 end if end sub sub procedure prepare_2_show_data ' Prepare data for send to MAX7219 for i = 0 to 31 dsp[i] = h_dsp[i] next i end sub sub procedure send_2_display() ' Send data to MAX7219 for i = 0 to 7 CS = 0 ' Begin transfer. SPI_Write(i+1) ' Send address. SPI_Write(dsp[i+24]) ' Send the value. SPI_Write(i+1) ' Send address. SPI_Write(dsp[i+16]) ' Send the value. SPI_Write(i+1) ' Send address. SPI_Write(dsp[i+8]) ' Send the value. SPI_Write(i+1) ' Send address. SPI_Write(dsp[i]) ' Send the value. CS = 1 ' Finish transfer. next i end sub sub procedure show_data() ' Show received data prepare_2_show_data send_2_display() end sub sub procedure alarm ' Buzz if PORTC1 = 1 if al = 0 then I2CW(0xf,0x0) end if PORTC.1 = flgal and al.0 and tal1 and tal end sub sub procedure init_main() OSCCON = %11111111 ' MCU clock at 16 MHz ANSELA = %00000000 ' All I/O pins of the PORTA are configured as digital ANSELC = %00000000 ' All I/O pins of the PORTC are configured as digital CM1CON0 = %00000000 ' Disbale comparator CM2CON0 = %00000000 ' Disbale comparator TRISA = %11111111 ' PORTA All Inputs TRISC = %00100000 ' PORTC All Outputs APFCON0.SDOSEL = 0 APFCON0.SSSEL = 1 INTCON.GIE = 1 ' Enables all unmasked interrupts INTCON.PEIE = 0 ' Disables all peripheral interrupts INTCON.T0IE = 1 ' Enables the TMR0 interrupt INTCON.INTE = 1 ' Enables the RA2/INT external interrupt INTCON.IOCIE = 0 ' Disables the PORTA change interrupt INTCON.T0IF = 0 ' TMR0 register did not overflow INTCON.INTF = 0 ' The RA2/INT external interrupt did not occur INTCON.IOCIF = 0 ' None of the PORTA <5:0> pins have changed state OPTION_REG.WUE = 0 ' PORTA pull-ups are enabled by individual port latch values OPTION_REG.INTEDG = 0 ' Interrupt on rising/falling edge of RA2/INT pin OPTION_REG.T0CS = 0 ' set Timer0 clock source to internal OPTION_REG.T0SE = 1 ' Increment on high-to-low transition on RA2/T0CKI pin OPTION_REG.PSA = 0 ' asign prescaler to Timer 0 OPTION_REG.PS2 = 1 ' asign prescaler value OPTION_REG.PS1 = 1 ' asign prescaler value OPTION_REG.PS0 = 1 ' asign prescaler value WPUA = %00111111 ' Pull-ups PORTA to be enabled WPUC = %00100000 ' Pull-ups PORTA to be enabled SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH) Soft_I2C_Init() ' Initialize I2C module SPI1_Init() ' Initialize SPI module btmp=0xB ' Set brtightness adress bright=I2CR(btmp) ' Read brtightness value if bright >15 then bright = 2 end if I2CW(btmp,bright) ' write bright btmp=0x0D ' Set Temp_On/Off adress grc=I2CR(btmp) ' Read Temp_On/Off value if grc > 1 then grc = 0 end if I2CW(btmp,grc) ' write Temp_On/Off adress btmp=0xC ' Set alarm on/off adress al=I2CR(btmp) ' Read alarm on/off value max7219_init() ' Initialize MAX7219 module PORTC.1 = 0 ' Do not start alarm on start_up I2CW(0xA,%10000000) ' Alarm when hours, minutes, and seconds match I2CW(0x0E,0) ' Square wave is output on the INT/SQW pin I2CW(0x10,0) ' Aging Offset TRISC.1 = 0 ' Because SPI1_Init make PORTC1 as input str = 0 j = 0 y = 0 k = 0 x = 0 x0 = 0 x1 = 0 x5 = 0 flgint = 0 pflgint = 0 flgal = 0 dp = 0 btset = 0 ytal = 0 tal = 0 tal1 = 0 CS=1 'I2CW(2,Dec2Bcd(23)) 'hour 'I2CW(1,Dec2Bcd(19)) 'min 'I2CW(0x0D,1) ' hour to temp 'I2CW(0x0C,0) ' alarm end sub sub procedure Interrupt() iv 0x0004 ics ICS_AUTO if INTCON.INTF = 1 then flgint = not flgint OPTION_REG.INTEDG = not OPTION_REG.INTEDG dp.0 = not dp.0 if dp.0 = 0 then Ow_Reset(PORTC, 4) ' Onewire reset signal Ow_Write(PORTC, 4, 0xCC) ' Issue command SKIP_ROM Ow_Write(PORTC, 4, 0x44) ' Issue command CONVERT_T else Ow_Reset(PORTC, 4) Ow_Write(PORTC, 4, 0xCC) ' Issue command SKIP_ROM Ow_Write(PORTC, 4, 0xBE) ' Issue command READ_SCRATCHPAD temp1 = Ow_Read(PORTC, 4) temp1 = (Ow_Read(PORTC, 4) << 8) + temp1 btmp.0 = temp1.4 btmp.1 = temp1.5 btmp.2 = temp1.6 btmp.3 = temp1.7 btmp.4 = temp1.8 btmp.5 = temp1.9 btmp.6 = temp1.10 btmp.7 = temp1.11 if btmp > 128 then tsgn = 16 btmp = not btmp + 1 else tsgn = 10 end if th0 = btmp Mod 10 th1 = btmp / 10 end if k = k + 1 if k = 23 then k = 0 end if INTCON.INTF = 0 End if if INTCON.T0IF = 1 then TMR0 = 61 y = y + 1 if ytal = 128 then ytal = 0 end if if ytal<64 then tal1 = 1 else tal1 = 0 end if if tal1 = 1 then if ytal mod 8 = 0 then tal = not tal end if else tal = 0 end if ytal = ytal + 1 if y = 20 then flsh = not flsh y = 0 end if ' buton mod if Button(PORTA, 3, 1, 1) then k4 = 255 end if if k4 and Button(PORTA, 3, 1, 0) then btset = btset + 1 if btset= 11 then btset= 0 end if btmod = stadrs[btset] k4 = 0 end if 'Button Up if btset <> 0 then if Button(PORTA, 5, 1, 1) then k0 = 255 end if if k0 and Button(PORTA, 5, 1, 0) then k0 = 0 x0 = 1 end if end if ' Button Down if btset <> 0 then if Button(PORTA, 4, 1, 1) then k1 = 255 end if if k1 and Button(PORTA, 4, 1, 0) then k1 = 0 x1 = 1 end if end if 'Button Al On/Off if Button(PORTC, 5, 1, 1) then k5 = 255 end if if k5 and Button(PORTC, 5, 1, 0) then x5 = 1 k5 = 0 end if INTCON.T0IF = 0 End if end sub main: ' Main program delay_ms(100) init_main() while TRUE select case btset case 0 ' show alt hour & temperature if flgint <> pflgint then pflgint = flgint read_RTC() prepare_to_show_hour(h1, h0, m1, m0, dp, al ) prepare_to_show_temp(tsgn, th1, th0) if grc = 1 then if k<=16 then if k=16 then dp = 1 prepare_to_show_hour(h1, h0, m1, m0, dp, al ) for yy = 0 to 31 hour2temp send_2_display() delay_ms(30) alarm() next yy else prepare_2_show_data send_2_display() alarm() end if else if k=22 then dp = 1 prepare_to_show_hour(h1, h0, m1, m0, dp, al ) for yy = 0 to 31 temp2hour send_2_display() delay_ms(30) alarm() next yy else prepare_to_show_temp(tsgn, th1, th0) for i = 0 to 31 dsp[i] = th_dsp[i] next i send_2_display() alarm() end if end if else show_data alarm() end if end if case 1 read_RTC() if flsh = 0 then h1 = 10 h0 = 10 end if prepare_to_show_hour(h1, h0, m1, m0, 1, 0 ) show_data() up_down() case 2 read_RTC() if flsh = 0 then m1 = 10 m0 = 10 end if prepare_to_show_hour(h1, h0, m1, m0, 1, 0 ) show_data() up_down() case 3 read_RTC() if flsh = 0 then d1 = 10 d0 = 10 end if prepare_to_show_hour(d1, d0, mo1, mo0, 0, 0 ) show_data() up_down() case 4 read_RTC() if flsh = 0 then mo1 = 10 mo0 = 10 end if prepare_to_show_hour(d1, d0, mo1, mo0, 0, 0 ) show_data() up_down() case 5 read_RTC() if flsh = 0 then y1 = 10 y0 = 10 end if prepare_to_show_hour(2, 0, y1, y0, 0, 0 ) show_data() up_down() case 6 read_RTC() if flsh = 0 then s1 = 10 s0 = 10 end if prepare_to_show_hour(10, 10, s1, s0, 1, 0 ) show_data() up_down() case 7 read_RTC() if flsh = 0 then ah1 = 10 ah0 = 10 end if prepare_to_show_hour(ah1, ah0, am1, am0, 1, 1 ) show_data() up_down() case 8 read_RTC() if flsh = 0 then am1 = 10 am0 = 10 end if prepare_to_show_hour(ah1, ah0, am1, am0, 1, 1 ) show_data() up_down() case 9 if flsh = 0 then br1 = 10 br0 = 10 end if prepare_to_show_hour(14, 15, br1, br0, 1, 0 ) show_data() up_down() btmp=0x0B bright=I2CR(btmp) ' brightness br0 = bright Mod 16 br1 = bright / 16 maxCMD(MAX7219_BRIGHTNESS, bcd2dec(bright)) case 10 btmp=0x0D btmp=I2CR(btmp) ' Temperature On/Off grc=btmp if flsh = 0 then grc = 10 end if prepare_to_show_hour(13, 12, 0, grc, 1, 0 ) show_data() up_down() end select if x5 = 1 then x5 = 0 if al <> 0 then al = 0 else al = 1 end if while not k5.0 prepare_to_show_hour(ah1, ah0, am1, am0, 1, 1 ) show_data() wend I2CW(0xc,al) ' Alarm On/Off I2CW(0xf,0x0) ' Clear alarm flag end if alarm() wend end. LE Cum se procedeaza a.i. codul sa apara intr-o caseta mai mica, ca in alte forumuri?
  9. mai simplu cu un 337 la ce ai tu nevoie
  10. Pune pe iesirea AO un repetor pe emitor cu tranzistor PNP BD136-140.
  11. Mi se pare gresita abordarea ta. Eu la PIC-uri evit cat pot sa folosesc delay-uri in aplicatiile pe care le scriu, doar intreruperi, si niciodata nu mi se blocheaza MCU chiar daca functioneaza nonstop (de ex ceasurile se opresc doar cand se ia curentul). Si nici quart-uri nu folosesc... doar in cazul cand trebuie sa am un clock foarte precis. In schimb sunt atent la definirea variabilelor, si la initierea registrilor. L.E. Si bineinteles proiectarea corecta a cablajului: trasee pentru intrari cat mai scurte, evitarea routarii acestora pe langa traseele de forta, decuplarea alimentarii MCU cat mai aproape de pinii corespunzatori cu un C de 100n, eventual in paralel cu unul de 10u daca mediul sau alimentarea are zgomot.
  12. Kreator

    Radio Gloria

    Buna ziua, O Gloria si Albatrosul il vreau eu. Am trimis si mesaj!
  13. Buna seara, Am achizitionat un transformator care se incalzea foarte tare chiar si in gol. L-am desfacut in ideea de a-l duce la rebobinat fiindca suspectam ca are spire in scurt. La "dezmembrarea" lui insa am observat ca tolele lui sunt foarte moi nu au rigiditatea tolelor din ferosiliciu cu care eram eu obisnuit. Tolele au rigiditatea si se comporta la indoire la fel ca o tabla ordinare din fier. E OK ca tolele sa fie asa? Va Intreb asta sa nu-l duc la rebobinat si sa constat ca se incalzeste iar din cauza ca tolele sunt din tabla ordinara. Va multumesc!
  14. Frumos proiect! Eu i-am pus si o iesire de -5V ( prinde bine uneori!)
  15. Sursa mea simetrica e inca in faza de concepere HW, programare SW, etc Ma incurca tare Volt-ampermetrele chinezesti ca nu pot fi conectate astfel incat sa am un GND comun...
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.