Hi Megahertz, the code below is tested for a PIC12F675, it's the Henrik's code but with 3 minor modifications (Sens var type, Aliases index, and inverted counter)
All the credit is to Mr. Olsson
Ivan.Code:#CONFIG __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF #ENDCONFIG DEFINE OSCCAL_1K 1 'Internal Clock Auto-cal (for reliable RS232) ansel=0 'Don't use ADC's cmcon=7 'Don't use analog comparators DEFINE DEBUG_REG GPIO 'Set Debug pin port DEFINE DEBUG_BIT 0 'Set Debug pin bit DEFINE DEBUG_BAUD 2400 'Set Debug baud rate DEFINE DEBUG_MODE 0 'Set Debug mode: 0 = true, 1 = inverted Sens VAR Byte ' 5bit array for sensor bits Sens1 VAR Sens[1] ' Aliases to the array bits. Sens2 VAR Sens[2] Sens3 VAR Sens[3] Sens4 VAR Sens[4] Sens5 VAR Sens[5] Multiplicator VAR WORD Value VAR WORD i VAR BYTE Begin: sens1 = 1 'Sensor 1 is high sens2 = 0 'Sensor 2 is low sens3 = 1 'Sensor 3 is high sens4 = 0 'Sensor 4 is low sens5 = 1 'Sensor 5 is high CalculateValue: Multiplicator = 1 Value = 0 For i = 5 to 1 step -1 ' Index the 5 sensor bits of the array IF Sens[i] THEN Value = Value + (i * Multiplicator) Multiplicator = Multiplicator * 10 ENDIF NEXT debug "Sensors : ",#value,13,10 pause 1000 goto begin





Bookmarks