Device = 16F877 'Declares 'ADC Declare Adin_Res = 10 '10 Bit Resolution 'Declare Adin_Res = 8 '8 Bit Resolution Declare Adin_Tad = 32_FOSC 'Declare Adin_Tad = FRC Declare Adin_Stime = 70 'XTAL Declare Xtal = 20 Declare LCD_ENPin PORTB.0 Declare LCD_RSPin PORTB.2 Declare LCD_RWPin PORTB.1 Declare LCD_Interface 8 Declare LCD_Lines 4 Declare LCD_DTPin PORTD.0 Declare LCD_Type 0 'Variables Dim CurrValue[6] As Byte Dim a As Byte 'General Variable for counting Dim b As Byte Dim VinRslt As Word Dim CinRslt As Word Dim CurrVolt As Float Dim Fuse As Float Dim Volts As Float Dim Curr As Float Dim VDDRef As Float Dim ResA As Float Dim ResV As Float Dim ZC As Float All_Digital = True TRISB = %01100000 'All of Port B is output TRISC = %10000000 'All of Port C is output PORTC.0 = 0 PORTB.4 = 0 PORTB.7 = 0 Fuse = 500.0 Cls DelayMS 500 Print At 1,1, "+ 00.0V 0500 mA " Print At 2,1, "Fuse = 0500 mA " Print At 3,1, "- 00.0V 0500 mA " Print At 4,1, "********************" VDDRef = 4.99024 'Start with the ideal world 5V ResV = VDDRef/1024 ResA = VDDRef/1024 For a = 20 To 1 Step -1 Print At 4,a, " " DelayMS 500 Next a Print At 4,1, "Fuse = 0500 mA " PORTB.4 = 1 'Switch on portB.4 to drive the relay TRISA = %00000111 'Select ADC pins for input ADCON1 = %10000000 'Set portA.0 to analog as apposed to digital as spesified earlier 'Voltage test Again: DelayMS 50 VinRslt = ADIn 0 'Read the value on portA.0 Volts = VinRslt * ResV Volts = Volts * 4.92 If Volts < 10 Then Print At 1,2," ",Dec2 Volts Else Print At 1,2,Dec2 Volts End If DelayMS 50 'Now read current CinRslt = ADIn 1 'Read the value on portA.1 CurrVolt = CinRslt * ResA If CurrVolt <= 2.50546 Then Curr = 0 ElseIf CurrVolt > 2.5 Then Curr = CurrVolt - 2.5 Curr = Curr / .1 Curr = Curr * 1000 'show mV as dec 0 Curr = fRound Curr 'Round it If Curr > Fuse Then 'Blow the fuse PORTB.7 = 1 Print At 2,1, "FUSED/RST or CHANGE " End If If PORTB.7 = 1 Then 'Do nothing until it is reset FUSER: Print At 2,20, "*" Print At 2,6, "*" DelayMS 100 Print At 2,20, " " Print At 2,6, " " DelayMS 100 If PORTB.6 = 0 Then 'Reset pressed DelayUS 50 Print At 2,1, "Fuse = 0" Print At 2,12,Dec1 Fuse Print At 2,15," mA " PORTB.7 = 0 DelayUS 50 GoTo Again Else GoTo FUSER End If End If End If Str CurrValue = " " Str CurrValue = Str$(Dec1 Curr) If Curr = 0 Then Print At 1,11, "0000" Else For b = 0 To 5 'Find the Decimal Point If CurrValue[b] = "." Then a = b End If Next b If a = 1 Then 'Single Integer Print At 1,11, "000",Str CurrValue\1 End If If a = 2 Then '2 Integer Print At 1,11, "00",Str CurrValue\2 End If If a = 3 Then '3 Integer Print At 1,11, "0",Str CurrValue\3 End If If a = 4 Then '4 Integer Print At 1,11, Str CurrValue\4 End If End If GoTo Again Stop