Archive for the 'Electronics' Category

PIC10F Assembly "Hello World"

So for a project, I’m using a PIC10F due to their very small size (in a SOT23-6, wow) and low cost.  They don’t have interrupt support, but they do have a timer, watchdog timer and a comparator.  You can do some fairly funky things with them.  However, I’m opting to use assembly for this project since it’s probably going to be simpler this way, as the stuff I need to do is very timing critical (reading sensors without interrupts = lots of polling).  Also I think I can squeeze the size of the program down better than a C compiler might do.

But I ran into a roadblock.  There are no documentations of assembly code listings for the PIC10F, and very few resources online.  So here’s a little snippet for you, which blinks an LED on pin GP2:

	list      p=10F222            ; list directive to define processor

#include
        ; processor specific variable definitions

    #define LightOn bsf GPIO,2  ; turn drive output on
    #define LightOff bcf GPIO,2 ; turn drive output off

;**********************************************************************
	ORG     0x1FF             ; processor reset vector
	ORG     0x000             ; coding begins here

    cblock 0x18 ; this is where we declare what to call user memory locations
      DelayTime:3       ; reserve 3 locations for delay counters
     endc

	goto Init
Start:
	clrwdt
	LightOn
	call Delay
	LightOff
	goto Start

Init:
    movwf   OSCCAL      ; load factory osccal value at start-up
    bcf     OSCCAL,0    ; do NOT output osc/4 on GP2 (IR sensor input)
    movlw   b'00000000' ; set all GPIO low at startup
    movwf   GPIO        ; load port latches
    movlw   b'00000000' ; All GPIO pins are outputs
    tris    GPIO        ; set I/O directions
    movlw   b'11011000'	; wake-up on pin change disabled, weak pull-ups off
                        ; Timer0 clock select on GP2 internal
    option              ; write to OPTION_REG

    ; clear all user RAM/variables on boot

    movlw  0x10         ; initialize pointer
    movwf  FSR          ; to RAM start
	goto Start

Delay					  ;
    movlw   D'2'          ; 2 = a delay period of approximately 500mS

Delay2                    ;
    movwf   DelayTime     ; pre-load W & enter at Delay2 for different delays
    movlw   D'232'        ;
    movwf   DelayTime+1   ;
    movlw   D'255'        ;
    movwf   DelayTime+2   ;
Dloop
    clrwdt                ; 1
    decfsz  DelayTime+2,f ; 1
    goto    $-2           ; 2/1
    decfsz  DelayTime+1,f ; 1
    goto    $-4           ; 2/1
    decfsz  DelayTime,f   ; 1
    goto    $-6           ; 2/1
    retlw   0             ; 2

	end

Delay routine and general structure is shamelessly stolen from Bruce on PICbasic.co.uk.

Hopefully, someone will find this useful :)

Things I currently dislike

I’ve been in the lab since I finished work 4 hours ago.  I’ve still not managed to get my embedded system board routed.  I’m annoyed with:

  • 40 pin TQFP packages
  • IDC connectors
  • OrCAD’s autorouter
  • Having to mix surface mount and through-hole components because I can’t be sure what package certain things are labeled as in OrCAD.

I’m going home now >_<

Cleaning LCD Screens

So, you’ve got a nice shiny laptop which you use every day. After a few months, the screen gets somewhat grubby and has marks on it. Ew. So you have to go to the computa shop and get some of those LCD screen wipes, right?

WRONG.

What’s really in those wipes? They’re just lint free cloths soaked in water and isopropanol alcohol! Why pay £10.00 for a load of wipes (which will probably dry out after a while) when you can make your own solution and use kitchen towel instead?

The process is easy. Just get some isopropanol, probably from Boots or another chemist, pour some into a jar or container. Add the same amount of water. Voila, you now have some screen cleaning solution. Approximately 50% isopropanol 50% water.

All you do now is get some kitchen towel or some other lint free cloth, dip it in and wipe the screen down. I then suggest you rub gently, and then dry off with the other end of the cloth. What usually happens is the isopropanol dissolves the crap on the screen, the excess evaporates (isopropanol is very volatile), and leaves the water, which you can then mop up taking the crap-in-solution with it. This is a similar process to how soap works, without a) damaging the screen and b) leaving residue on the screen.

So there is a handy tip for all your laptop-cleaning needs!