Nadat ik het dummyload project had afgemaakt, dacht ik eraan dat dit project dezelfde displays gebruikt. De code kon ik dus vrijwel compleet overnemen. Daarom heb ik dit project nu dan ook afgemaakt. De pic in dit project is uiteindelijk een 16F1825 geworden welke op 32Mhz draait.
De code:
'**************************************************************** '* Name : Scheidingstransformator V2 * '* Author : Stijn Coenen ElektronicaStynus.be * '* Notice : Copyright (c) 2013 Stijn Coenen (Stynus) * '* : All Rights Reserved * '* Date : 01/05/2013 * '* Version : 1.3 * '* Notes : This code is provided to you as is, without * '* : warranty of any kind.Use at own risk!! * '**************************************************************** Device = 16F1825 Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_ON, MCLRE_OFF, CP_OFF, CPD_OFF, BOREN_OFF, CLKOUTEN_OFF, IESO_ON, FCMEN_ON Config2 WRT_OFF, PLLEN_ON, STVREN_OFF, BORV_19, LVP_OFF Xtal = 8 '**************************************************************** 'EN: Declarations 'NL: Declaraties 'Displays Symbol Disp_klok = LATC.5 Symbol Spanning_Data = LATC.4 Symbol Spanning_Latch = LATC.3 Symbol Stroom_Data = LATC.2 Symbol Stroom_Latch = LATC.1 'EN: Measurement values 'NL: Meetwaardes Dim Spanning As Word Dim Stroom As Word Symbol N_Samp_U = 15 Dim GemU[N_Samp_U] As Word Symbol N_Samp_I = 15 Dim GemI[N_Samp_I] As Word 'EN: Display values 'NL: Display waardes Dim DispSpanning As Byte Dim DispStroom As Byte Dim DispArU[3] As Byte Dim DispArI[3] As Byte Dim IntCase As Byte Dim IntX As Byte Dim IntDisp As Byte Dim X As Byte Dim Temp As Byte 'EN: Settings AD converter 'NL: Instellingen AD converter Declare Adin_Res 10 Declare Adin_Tad FRC Declare Adin_Stime 250 'EN: Connections 7 segment displays on the 74HC595 pcb's 'NL: Aansluitingen 7 segment displays aan de 74HC595 op de printjes 'dPecgbfa Symbol Nul = %01001000 ' a '0 Symbol Een = %11101011 ' ##### '1 Symbol Twee = %01010010 ' # # '2 Symbol Drie = %01100010 ' f # g # b '3 Symbol Vier = %11100001 ' ##### '4 Symbol Vijf = %01100100 ' # # '5 Symbol Zes = %01000100 ' e # d # c '6 Symbol Zeven = %11101010 ' ##### '7 Symbol Acht = %01000000 '8 Symbol Negen = %01100000 '9 Symbol Uit = %11111111 'Out Symbol Streep = %11110111 'Bar 'EN: Connections of the transistors On the 74HC595 pcb's 'NL: Aansluitingen Transistoren aan de 74HC595 op de printjes Symbol disp1 = %00001100 Symbol disp2 = %00001010 Symbol disp3 = %00000110 'EN: Misc 'NL: Diverse Symbol TMR0IF = INTCON.2 'Tris registers TRISA = %11111111 TRISC = %00000000 All_Digital = true On_Hardware_Interrupt GoTo Interrupts '**************************************************************** Opstarten: 'EN: Set clock to 64 Mhz 'NL: klok instellen op 64 Mhz OSCCON = %11110010 Clear 'ram 'EN: Timer0 setup to drive the displays 'NL: Timer0 instellen om de displays aan te sturen OPTION_REG = %00000111 INTCON = %10100000 'EN: Settings AD converter 'NL: Instellingen AD converter ADCON1 = %10110000 GoTo Main '**************************************************************** Interrupts: Context Save If TMR0IF = 1 Then TMR0IF = 0 'Reset flag TMR0 = 230' 'Preloard timer 'EN: Loading data for the display that is driven this interrupt 'NL: Data inladen voor het display dat deze interrupt wordt aangestuurd DispSpanning = DispArU[IntCase] DispStroom = DispArI[IntCase] 'EN: Get the transistor settings and set the decimal point 'NL: Transistoren info uitlezen en de comma aanzetten Select IntCase Case 0 IntDisp = disp1 Case 1 IntDisp = disp2 Case 2 IntDisp = disp3 DispStroom.6 = 0 Case Else IntDisp = 255 IntCase = 0 EndSelect 'EN: Outputting transistors data 'NL: Transistor data inklokken For IntX = 0 To 7 Spanning_Data = IntDisp.7 Stroom_Data = IntDisp.7 Disp_klok = 1 IntDisp = IntDisp * 2 Disp_klok = 0 Next 'EN: Outputting display data 'NL: Display data inklokken For IntX = 0 To 7 Spanning_Data = DispSpanning.7 Stroom_Data = DispStroom.7 Disp_klok = 1 DispSpanning = DispSpanning << 1 DispStroom = DispStroom << 1 Disp_klok = 0 Next 'EN: Latch data to the outputs of the 74hc595 ic's 'NL: Data naar de uitgangen van de 74hc595 ic's latchen Spanning_Latch = 1 Stroom_Latch = 1 'EN: Set counter for next interrupt 'NL: Teller bijtellen voor volgende interrupt Inc IntCase If IntCase > 2 Then IntCase = 0 EndIf Spanning_Latch = 0 Stroom_Latch = 0 EndIf Context Restore Return '**************************************************************** Main: While 1 = 1 'EN: Voltage measurement 'NL: Spannings meting For X = (N_Samp_U - 1) To 1 Step -1 GemU[X] = GemU[X-1] Next Spanning = ADIn 0 Spanning = Spanning /10 Spanning = Spanning - 4.95 GemU[0] = Spanning * 3.25'3.03 Spanning = 0 For X = 0 To (N_Samp_U - 1) Spanning = Spanning + GemU[X] Next Spanning = Spanning / N_Samp_U 'EN: Current measurement 'NL: Stroom meting For X = (N_Samp_I - 1) To 1 Step -1 GemI[X] = GemI[X-1] Next Stroom = ADIn 1 Stroom = Stroom - 55 'Offset GemI[0] = Stroom /4.28 Stroom = 0 For X = 0 To (N_Samp_I - 1) Stroom = Stroom + GemI[X] Next Stroom = Stroom / N_Samp_I 'EN: Calculate value's for on the display 'NL: Meetwaardes naar display berekenen For X = 0 To 2 Temp = Dig Spanning, X DispArU[X] = LRead Cijfers + Temp Temp = Dig Stroom, X DispArI[X] = LRead Cijfers + Temp Next 'EN: Delay for slower display update 'NL: Wachten om het display niet te snel te updaten DelayMS 75 Wend '**************************************************************** Cijfers:- LData Nul, Een, Twee, Drie, Vier, Vijf, Zes, Zeven, Acht, Negen, Uit, Streep End
Bestanden:
Code file: Download
Hex file: Download
PCB bestanden meter print: Download