Ride into work

I was going to try and ride into work via the Westgate punt tomorrow, but it turns out the punt is closed indefinately on weekdays! I’m guessing I dont need to go to bed early tonight :( />

A while ago I wade up a bike light using the awesome light brain project on the net.
This allows You to ran a high wattage bulb at low power with very high efficiency

The original project uses an 672 pic clip, I bought a pic 675 chip based on the statement that it works on a 675 chip with minor modifications.
Below are the changes I made to get it going on the 675. Edit the original uc4diy22.asm file and replace the red text with the green text :)

Reflect new cpu type

< list p=12c672 ; list directive to define processor
< #include ; processor specific variable definitions
> list p=12f675 ; list directive to define processor
> #include ; processor specific variable definitions

Different IO pins
< #define button GPIO, 3 ; momentary button (active low)
< #define lamp GPIO, 2 ; PWM output (FET drive)

> #define button GPIO, 2 ; momentary button (active low)
> #define lamp GPIO, 5 ; PWM output (FET drive)

Different memory layout
< ORG 0x7FF ; program location for factory cal value
< retlw 0x98 ;12C672JW oscillator cal value

> ORG 0×3FF ; program location for factory cal value
> retlw 0×68 ; oscillator cal value


Different A to D initialise in ADCON0 register

< movlw 45> movlw b’00000011′ ;; Go/done, ADON - FOSC set in ANSEL

More A to D
< movf ADRES, W ; read A/D result into "voltage"

> movf ADRESH, W ; address is MSB, what we want (with ADFM set to 0 in ADCON0 reg)

Different Oscillator calibration value (again…)

< call 0x7FF ; get factory oscillator calibration value

> call 0×3FF ; get factory oscillator calibration value


Set Digital or Analogue pins and input or output direction
< movlw 06
< movwf ADCON1 ; GPIO, 0 is analog input, all others digital
<
< movlw b'00011001'
< movwf TRISIO ; set directions for GPIO port


> movlw b’00010001′
> movwf ANSEL ; dont touch :) set ad0 as analogue - last 4 bits. fosc/8
>
> movlw b’00000111′
> movwf TRISIO ; set directions for GPIO port, 1=in, 0=out

GPIO
< movlw b'00001000'

> movlw b’00000010′
> movwf IOC
>
> movlw b’00011000′

Different A/D turnon (part 1)

< movlw 41
< movwf ADCON0 ; turn A/D on

> movlw b’00000001′
> movwf ADCON0

Different A/D turnon (part 2)

< movlw 41
< movwf ADCON0 ; turn A/D ON (Fosc/8, channel 0)


> movlw b’00000001′
> movwf ADCON0
Different A/D turnoff

< movlw 40
< movwf ADCON0 ; turn AD off to conserve power