rem Simple code to make a PIC12F675 blink GP0 on and off rem but only if it correctly computes other stuff first (11/13/12) ;this comment not output to assembly file raw ;this text passed as-is to assembly file rem assembler-specific directives asm list p=12f675 asm radix dec asm include asm __CONFIG _WDT_OFF & _MCLRE_OFF & _PWRTE_ON & _CP_OFF & _CPD_OFF & _INTRC_OSC_NOCLKOUT asm errorlevel -302 ;suppress gpasm messages about not being in bank 0 define hiregs = STATUS.RP0 ;for banking define pindirs = 00000000B ;all outputs define outpin = GPIO.0 ;output pin define ConstA = 11 ;delay constants define ConstB = 86 define ConstC = 166 byte CounterA ;for timing delay byte CounterB byte CounterC GOTO start ;jump to actual start asm ORG 8 start: ;start of program code GPIO = 0 INTCON = 0 ADCON0 = 0 T1CON = 0 CMCON = 7 bitset hiregs ANSEL = 0 PIE1 = 0 WPU = 0 IOC = 0 OPTION_REG = 11001101B TRISIO = #pindirs bitclear hiregs rem validate stuff rem goto hang if error byte VarA byte VarB byte VarC VarA = 10 VarB = 5 VarC = VarA + VarB VarC = VarC + VarA if VarC <> 25 goto hang if VarC < 25 goto hang if VarC > 25 goto hang if VarC = VarA goto hang if VarC <= VarA goto hang if VarA >= VarC goto hang if VarC = 25 then if VarC >= 25 then if VarC <= 25 then increment VarA if VarA >= 10 then VarA = VarA - 2 if VarA <= 8 then goto hang else decrement VarA VarA = VarA + 1 VarA = VarA - 1 if VarA = 8 goto domorecomp endif endif endif endif endif goto hang domorecomp: VarA = 10 VarB = 11 if VarA >= 10 then if VarB <= 11 then if VarA > 9 then if VarB < 12 then if VarA < VarB then if VarB > VarA then goto compok endif endif endif endif endif endif goto hang compok: array ArrayD(6) ArrayD(0) = 0 ;note array elements start at 0 ArrayD(1) = 2 ArrayD(3) = 4 ArrayD(5) = 7 VarB = ArrayD(5) if VarB <> 7 goto hang VarB = ArrayD(1) if VarB <> 2 goto hang VarA = 3 VarB = ArrayD(VarA) if VarB <> 4 goto hang VarA = 0 VarB = ArrayD(VarA) if VarB <> 0 goto hang rem test bit stuff byte Bits bitset Bits.0 bitcopy Bits.1 = Bits.0 bitcopy Bits.2 = not Bits.1 if not Bits.0 goto hang if not Bits.1 goto hang if Bits.2 goto hang if Bits.0 then if Bits.1 then if not Bits.2 then goto bitsok endif endif endif goto hang bitsok: rem test other stuff VarA = 10000001B shift VarA left if VarA.1 then if not VarA.0 then if not VarA.7 then bitset VarA.7 shift VarA right if not VarA.7 then if VarA.6 then goto shiftok endif endif endif endif endif goto hang shiftok: VarA = 20 VarB = 3 VarA = VarA + 2 VarA = VarA - VarB if VarA <> 19 goto hang VarA = #0xFF ;must use # for immediate VarA = not VarA if VarA <> 0 goto hang VarA = VarA or #00000101B if VarA <> #00000101B goto hang VarA = VarA and #00000110B if VarA <> #00000100B goto hang VarA = VarA xor #11111111B if VarA <> #11111011B goto hang blinkloop: bitset outpin gosub delay bitclear outpin gosub delay goto blinkloop delay: loop CounterC from #ConstC loop CounterB from #ConstB loop CounterA from #ConstA next CounterA next CounterB next CounterC return hang: goto hang asm end