The test equipment troll, are you buying the right equipment?

Everyone was the noob at some point; I get it, it’s easy to get hung up on the blinking lights and things with screens but shelf it! You don’t need the $4,000 Agilent or Tektronix scope… though don’t get me wrong it’s on my wishlist too.  I bite my lip on the message boards when I see a new-to-electronics DIYer who wants to buy a Programmable DC Load as one of their very first pieces of test equipment; to troll or not to troll?

What kind of “maker” are you? there seem to be a couple types of DIYers/makers out there. This is my attempt at stuffing you neatly into one or two of these general groups:

1. The arduino/raspberry pi maker.

2. The analog hacker

3. The experienced super nerd/internet “teachers” (FPGAs, 2.4+GHz RF experiments, SDRs, etc.. )

4. Robo-geeks

5. Solar/”Free”-Energy/electric car makers

I don’t really fit neatly into any one category in that list, and perhaps you don’t either? But if you’re truly a noob you’re doing to sit fairly solid into a of those groups; it’s really not group 3 though, right? Where do you fit? Maybe I missed one.. I’m not against revising this blog post to improve it.. got feedback? I’ll reconsider my list.

First off, everyone needs a solderless breadboard. You should have some kind of power supply for it. I recommend one of those cheap power supply boards made for breadboards and fits into both rails of a solderless breadboard that will generate 5VDC and 3.3VDC. Here is an example found at Tindie: Dual Breadboard Power Supply (all links open in a new window). I’ve always used the Jameco or 3M precut wire jumpers because they look nice and when you put them on a soldered protoboard for permanent use they look nice. However, recently I also started using those breadboard jumper kits you can find all over (example). I’ve been won over.. they are a huge time saver. Then purchase your hand tools, a wire stripper, small screw drivers, a small wire cutter.. and so on. Hand tools are something you can probably figure out yourself and you can usually almost everything locally.

Okay, so back to that list of electronics-type internet personalities…

1. So you’re new… who are you? Got that sweet new Raspberry Pi and you’re determined to make it do something cool? Blinking LED light, check! What do you need for test equipment now?

Somethings you’ll need:

Soldering Iron: You’re going to want to interface your Pi to the world, that means adapters, you’re going to have to solder. Don’t invest a ton of money right away, a little 25-35 watt iron will do just fine. Later on you’ll end up investing in some SMD equipment if you start making your own PCBs… wait until you know what you’re doing until you’re dropping cash on a Metcal system.

Multimeter: If you have a nice meter that’s handy but the reality is you’ll probably only be measuring voltage and resistance for the time being. Get something affordable and save your money for the next piece of equipment!

Logic Analyzer: Yep, I know tons of people will disagree but they probably don’t “fit” into the same category as you. I don’t have a logic analyzer, I use a scope and I hate it. I plan on buying a Saleae logic analyzer after Christmas (assuming I don’t get one as a gift). I hate programming my PICs without a LA. I have needed one on the last 4 or 5 projects I’ve worked on. A 8 channel unit will probably work fine, but if you have the cash a 16 channel is preferred. Make sure you can get one that can be set up for protocol detection/translation/monitoring(or whatever they want to call it) like.. make sure it does I2C. There are a lot of used stand-alone units from e-bay: Steer clear! if you have a huge income by a MSO, or a new LA. Those older units usually don’t have (all/some of) the cabling, are missing software, or are going to take up way too much precious bench room.

That’s it besides the common hand tools for small work. You will need other pieces of equipment as you pick projects you’re dedicated to finishing. Wait until then, save your money because you’ll likely find out you need something special and you’ll need it yesterday. Maybe a signal generator? Maybe you’ll cross into the analog work and you’ll need that oscilloscope. I do recommend buying a cheap used Tektronix analog scope if end up needing one. It’s most likely if you’re new you don’t need over 100MHz scope.. then save your cash for the MSO or you’ll just be another guy with 6 scopes sitting around you shop when you could’ve bough a ton of other equipment.

One last tid bit:I lot of new makers are Arduino users, and that’s cool if it got you into the hobby; they seem decent? I don’t own any, I have a love for the PIC microcontrollers, I think you should give them a try sometime.

2. Does anyone just decide to be an analog hardware hacker? Maybe you work on pinball machines, or retro TTL interfacing with old composite TV signals, audiophile, a ham just starting in RF? A lot of options here… this is where I started.

Okay you do need a scope, no way around it. I still recommend a eBay Tektronix scope, or if you have the money go MSO. I don’t trust the cheap Chinese stuff but if you feel comfortable with it, do what you have to do but you’ll probably get better performance out of a Tek 465 or 2246 than you will a $400 LCD toy from overseas. You can usually pick up an old 20Mhz “starter” scope for $20 at a ham swap, I would guess 98% of my use of a scope can be done with a 20MHz scope and for the first few years of my tinkering I never noticed a need for anything more.

You’ll need a signal generator. Used is fine if you trust your scope’s calibration or you don’t need precision… you’ll need a variable power supply, (dual +/-), the multimeter. I prefer using my Agilent bench meter but I also have three Fluke handheld meters. (87, 187, 73). Start out with what you can afford.

You’ll also need a solid soldering iron. I hate recommending these, but if I was I’m partial to the Weller brand. My next iron will be the WD1002. You can start with a 25-35W iron until you can afford more if needed.

I think analog hackers will end up spending the most money out of all the newbies… be careful. It’s easy to spend too much money on equipment you don’t really need and then need a ton more test equipment you have something you need specific to a project and no more cash to buy. Start with the original basics and then buy as needed. If you can save money and buy something that will work for more than just your current project. I keep a running tally of all the projects I’m working on and what I need (or what I think I need!) for them. I generally bulk orders for parts together and if I need test equipment I try to buy something I can use more than once.

3. yeah right, you’re asking the wrong person… fit yourself into a different category if you’re starting out. Take a look at W2AEW’s lab… or that South African YouTube vlogger (mlmorton I think?) .. that guy must have held up a test equipment store..  I can’t even guess how much is labs is worth.

4. Robo-geeks! You’re going to have it rough. You do a little bit of analog work, motor control, digital logic, programming.. I hope you have a lot of money unless you’re content with soldering kits.

You’re going to want to start with a decent soldering iron, you’re going to use it a lot if you’re serious.

A multimeter… that’s it. You need to save your money for all that machining, CNC equipment!

Okay, just kidding, kind of. You will need plenty of other equipment but it’s going to really depend what kind of robots you’re building and at what level. I’ve seen a lot of people crew up and work on certain parts of a robot. Start with the basics and work yourself into what you’re interested in. You’re likely going to fit into one of the first two groups or perhaps both unless you’re just the guy on the controls or strictly writing software.

5. I’m sorry to offend some of you solar or e-car guys sticking you with the perpetual motion machine guys (and gals!). If you’re “making free power” … go get yourself some PPE and a Tesla coil then I recommend a book on Physics and Electronics 101, and call it a day. The rest of you probably don’t really need much past a multimeter. You’ll want something durable don’t go with one of those cheap-o $20 home depot meters.. if anyone needs a bulky Fluke it’s you! The rough environments and mechanical tools boxes.. do yourself the favor. If you find yourself needing something else then go and ask around, but if you’re load testing batteries? Save some cash and go find a cheap load. Small baseboard heaters make cheap loads, you can also get some large surplus resistors at reasonable rates but don’t buy a programmable DC load to test your batteries..

One last thing: Solar Electric?! Unless you have to go off grid (a lot) or you’re rolling in an RV and want a battery charger stop wasting your money. Solar hot water is definitely the way to go as long as you have a decent amount of sun/M2C

Okay, there is a LOT of test equipment out there for you to buy and you will need a lot of it as you take on projects. I have a bench full of test equipment, a bunch on shelving in the garage and I still have a running list of things I want to buy in the semi-near future.. my list:

HV Power Supply
Programmable Power Supply
Programmable Load
MSO Scope
Spectrum Analyzer
RF Signal Generator
Oscilloscope 4 Channel
Arbitrary Function Generator

I have a lot of older equipment, plenty of it was bough for one project and entirely inadequate for others, I also have a lot of ham radio equipment like a HP universal bridge, Bird Watt meter, etc, etc etc.. most of my “affordable” test equipment came from ham swaps and eBay.. ham radio clubs can be a great source for pairing up with people interested in electronics (just avoid the guys with lightbars and more than 3 antennas on their vehicles… trust me.. avoid them).

Oh and on a final note: Dear Tektronix/Fluke, I would will like some of your equipment … a lot of it in fact, used it good! I’m not too picky 🙂 I promise to show it off often and I live like 5 miles away from you.. I’ll pick it up!

TYMKRS Rotary Encoder + TAUTIC 20 Pin Dev Board PIC Test/Code

I got an order from Tindie last night. I had issues with my DIY stepper based rotary encoder so when I saw TYMKRS “Turn Me v1” kit I had no hesitation parting with $10. It seemed to only come with Arduino sample code so I wrote my own code. My code is written in assembly for the PIC because that’s my preferred microcontroller and I’m not much of a C programmer. I happened to get another pair of Jayson Tautic’s 20 Pin Development Boards. Check out his Tindie store.. he has a bunch of interesting things. If I still lived in the midwest I’d pick up that lightning detector. (Jayson, if you ever read this your fan’s request more awesomness)

These wasn’t a ton of sample code online … some 16F88 code I didn’t care for… 16F84 code that was wretched… and some interrupt driven code I wasn’t feeling either so I wrote my own polling code from scratch. It’s commented enough to get what I was doing. The schematic should be fairly obvious, not counting the LED resistors I used a pull down resistor on the switch built into the encoder.

To my knowledge, while writing the code, I had my very first stack overflow bug!

I received the rotary encoder yesterday and I had another pair of Tautic's 20 pin development boards show up the day before. The 20 pin dev board comes with a Microchip PIC 16F1509.
I received the rotary encoder yesterday and I had another pair of Tautic’s 20 pin development boards show up the day before. The 20 pin dev board comes with a Microchip PIC 16F1509.
A few pieces, this went together in a few moments. The unlabeled connector side of the board is just support.
A few pieces, this went together in a few moments. The unlabeled connector side of the board is just support.

The important stuff:

;*******************************************************************************
;   Rotary Encoder Test, 2 bit                                                                              *
;   http://www.iradan.com
;
;   RA0:    OUT     TEST LED
;   RA1:    IN      ENC_B INPUT, NOTE: DISCONNECT OR INSURE LOW WHEN PROGRAMMING
;   RA2:    IN      ENC_A INPUT
;   RB5:    OUT     SWITCH STATUS LED
;   RB7:    IN      SWITCH INPUT
;   RC<0:7> OUT     ENCODER "COUNT"
;
;   VERSION 0.1     INITIAL CODE
;
;*******************************************************************************

    errorlevel -230, -302, -303, -313
    LIST R=DEC

#include "p16f1509.inc"

    __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _CLKOUTEN_OFF
    __CONFIG _CONFIG2, _LVP_OFF & _STVREN_ON

            UDATA_SHR
COUNT       RES .1
ENC_LAST    RES .1
ENC_CURRENT RES .1

#DEFINE ENCA    PORTA,1
#DEFINE ENCB    PORTA,2
#DEFINE ENC_SA  ENC_LAST,0
#DEFINE ENC_SB  ENC_LAST,1
#DEFINE ENCA_NOW    ENC_CURRENT,0
#DEFINE ENCB_NOW    ENC_CURRENT,1

;*******************************************************************************
; Reset Vector
;*******************************************************************************

RES_VECT  CODE    0x0000            ; processor reset vector
    GOTO    START                   ; go to beginning of program

;*******************************************************************************
; MAIN PROGRAM
;*******************************************************************************

MAIN_PROG CODE                      ; let linker place main program

START
    CALL    INIT

    BANKSEL PORTA
    BSF     PORTA,0         ;THIS WAS FOR TESTING.

    GOTO    LOOP

INIT
    CLRF    COUNT

    BANKSEL PORTC
    CLRF    PORTC
    BANKSEL LATC            ;Data Latch
    CLRF LATC               ;
    BANKSEL ANSELC          ;
    CLRF ANSELC             ;Digital IO
    BANKSEL TRISC           ;
    MOVLW   B'00000000'     ;RC<0:7> OUT
    MOVWF   TRISC

    BANKSEL PORTA           ;
    CLRF PORTA              ;Init PORTA
    BANKSEL LATA            ;Data Latch
    CLRF LATA               ;
    BANKSEL ANSELA          ;
    CLRF ANSELA             ;digital I/O
    BANKSEL TRISA           ;
    MOVLW B'00111110'       ;Set RA<0,6:7>out RA<1:5> in
    MOVWF TRISA             ;

    BANKSEL TRISB
    MOVLW   B'11011111'     ;RB<5> OUT, RB<0:4>,<6:7> IN
    MOVWF   TRISB
    CLRF    PORTB

   BANKSEL OSCCON           ;SET OSCILLATOR SPEED
    MOVLW   0x78            ;01111000  / 16MHz
    MOVWF   OSCCON

    CLRF    ENC_CURRENT     ;HOUSE KEEPING
    CLRF    ENC_LAST

    RETURN

LED
    BANKSEL PORTB           ;THIS TURNS ON SWITCH STATUS LED
    BSF PORTB,5
    RETURN

INCR
    INCF    COUNT,f
;   GOTO    RESUME
    RETURN

DECR
    DECF    COUNT,f
;    GOTO    RESUME
    RETURN

DETERMINE_DIRA
    BTFSC   ENCB_NOW        ;OKAY WHICH WAY DID IT TURN?
    CALL    INCR            ;INCREMENT
    BTFSS   ENCB_NOW
    CALL    DECR            ;DECREMENT
    RETURN

TESTLASTA
    BTFSS   ENC_SA          ;SO ENCA WAS HIGH, WAS IT LAST TIME?
    CALL    DETERMINE_DIRA  ;YEP..
    NOP                     ;GUESS NOT, RETURNING
    RETURN

TEST_ENC                    ;I'M ONLY TESTING FOR A HIGH ON ENC A.
    BTFSC   ENCA_NOW        ;THAT MEANS EVERY OTHER TICK ON THE ENCODER
    CALL    TESTLASTA       ;DOES NOTHING
    RETURN

LOOP
    NOP

    BANKSEL PORTB
    BCF PORTB,5             ;TURN OFF SWITCH STATUS LED
    BANKSEL PORTA
    BTFSC   PORTA,5         ;TEST IF SWITCH IS PUSHED
    CALL    LED             ;BRANCH IF ON, SKIP IF NOT
    NOP

    BCF ENCA_NOW            ;CLEAR CONTENTS OF ENCODER "NOW BITS"
    BCF ENCB_NOW

    BANKSEL PORTA
    BTFSC   ENCA
    BSF     ENCA_NOW        ;ENC_A INPUT IS HIGH
    NOP
    BTFSC   ENCB
    BSF     ENCB_NOW        ;ENC_V INPUT IS HIGH

    CALL    TEST_ENC        ;TEST ENC_A

    BANKSEL PORTC           ;DUMP ENCODER COUNT ONTO PORTC
    MOVFW   COUNT
    MOVWF   PORTC

    BCF     ENC_SA          ;SAVE STATUS OF ENCODER A & B INPUTS
    BTFSC   ENCA_NOW
    BSF     ENC_SA

    BCF     ENC_SB
    BTFSC   ENCB_NOW
    BSF     ENC_SB

    BANKSEL PORTA           ;USED FOR TESTING
    BCF     PORTA,0

    GOTO LOOP               ;LOOP FOREVER

    END

 

Programmable Load Circuit Update

My unfortunate failure Friday lead me to banish the project to the “maybe-I’ll-work-on-this-later” pile. I decided to give it another look this morning. I figured I did it to myself when I decided to trust a random schematic found online instead of engineering my own, right? So I designed my own circuit, not that it’s rocket science… It worked fine. I will reconfigure the operational amplifier to be a voltage doubler; right now I am using a potentiometer to drive the MOSFETs but I’ve started to work on a program on a PIC mcu and the 0-5V out of the DAC isn’t going to do the trick…  I have a real nice book on Op Amps but this app note, AN-31, gives you plenty of examples if you every get bored one weekend and want to experiment with Op Amps. Also W2AEW (google it) has a great Youtube video on it that even the skilled will enjoy. If you’re working with interfacing microcontrollers you should buffer your outputs. A voltage follower Op Amp works well with DACs but keep in mind you’ll want to pick your Op Amp wisely.. think rail-to-rail or plan on using additional power.

Note to self: Build a quick “MOSFET” tester… I found many my recycled MOSFETs pulled off the odd piece of HAM swap meet scores were not totally functional.

So I tested my circuit up to 30 watts, mostly because I didn’t have a dummy load that could handle anything more. I’ll design up a circuit or photograph a hand drawn one once I’m done. I don’t know how much I’ll get done this week, I have jury duty, bleh!

On a side note: See the plastic cases on my bench with the white labels in the photo? I don’t think I’ve mentioned it but those are my parts storage. They are meant for 4×6″ photo storage bought from craft stores. I have eight cases of 20 of those storage boxes… and I’ve just filled all of them. I’ll have to buy another case in a while when I separate more parts.. the parts cases cost about $40 for the larger case that contains the 20 smaller cases. They are by far the best parts storage I’ve ever had. I still have a couple other types of storage for projects, wire, big parts like transformers, etc.. but for all the regular stuff these are a dream come true.

The meat and potatoes of the load work fine... note to self: stop trusting online circuits.
The meat and potatoes of the load work fine… note to self: stop trusting online circuits.

Simple 3 Phase Power Circuit

I have (had?) a desire to power a three phase motor from a disc drive earlier this afternoon. I don’t have a handy off the shelf inverter/3 phase signal generator so I decided to make one from what I had lying around. Using two 74LS74 Dual D Flip-Flops and any old square wave generator for a clock ( a LM555 will work ) I built a circuit in the configuration in the photos shown. The the 3 flip-flops are set up as a Johnson Counter. I started my circuit with a low-frequency and some LEDs on the outputs (don’t forget a couple hundred ohm current limiting resistor) because I don’t have a quad input scope. No real gotchas here other than making sure you tie /CLR and /PRE high. Don’t mind the third chip on the board, It was a AND gate from something else.

[Dear Tektronix, Please hook me up with a sweet quad input MSO and I’ll forever brag and show it off, I swear! No shipping needed I’ll pick it up in Everett, WA]

Next, and not shown, I’ve used TI’s FilterPro to design a low pass filter to get a sine wave. FilterPro is free software, good stuff. Now all you need to do is feed your circuit 6x the desired output frequency  to get your three-phase output. What I love about this circuit is the two 74LS74 chips have date codes that make them 2 months older than I am (circa 1976). No big deal because of the low frequencies. I will probably set up a PIC with a LCD to generate a 50% duty cycle PWM output to vary the frequency and then design some amplification on the back-end of the filters. I read somewhere the drives run 43kHz? and around 9V or so…

Like that sweet bread board? I won it free from Digikey on their Facebook page last winter, I hope they do that contest again this year!

If you’re reading this blog historically oldest to newest you’ve noticed I’ve benched the programmable load.; I’ll tinker with that some more later on this weekend and make mention of it in a post later on.

The simple TTL three phase signal generator with 400Hz output.
The simple TTL three phase signal generator with 400Hz output.
The three phase signal generator schematic and layout on a breadboard using 74LS TTL logic.
The three phase signal generator schematic and layout on a breadboard using 74LS TTL logic.

 

Woes of tinkering: Sleep

Constant Current Load gremlins: 2

Me: 0

Leaving a project in the middle of getting your @$$ handed to you is no fun. I hope I’m not the only one who gets a little frazzled when I have to leave the work bench before I get to fix the “big hold up”.. or magic bug.. or whatever it is that’s keeping your blinking light from doing it’s thing.

Kerry Wong came up with a Constant Current Load that was tweeted the other day. I bought some parts from digikey and went to work this weekend. Friday evening I designed and etched a simple board for the IRFP150Ns and shunts… then Saturday I had a little time in the morning and strip boarded the op amp circuit with a potentiometer input. I have a PIC dev board I bought from ebay that I’ll use but I’ll go into that another day. Saturday we lost power in a storm and Sunday I was suckered into installing wall heaters for my sister.. so a very tired Monday and Tuesday evening I have been tinkering with this thing… it’s not entirely obvious what I did wrong… probably a little error I’ll catch after catch up a bit on sleep.

I’m planning on using this for a constant current power supply. I believe Dave (EEVBlog) or perhaps someone else came up with a similar idea but they were using it for a way of testing batteries. I recommend just buying a West Mountain Radio CBA (computerized battery analyzer) if that’s the route you are going. The software is  pretty decent. I have a CBA-III but it only works on Windows XP.. I was pretty annoyed when they didn’t come out with a user updatable firmware patch for Windows 7. It’s a solid tool if you work with SLAs  or lithium batteries regardless of my little rant a couple years back.

So my primary laptop is a 1 year old Vaio that took a nasty dive at a science fair I was demonstrating my Sumo RoombaBot for a high-cap school. The USB boards died because it sheered the driver off the PCB and blew out traces, etc… no fixing it anyways. I have an old XP laptop I program for now but I was considering one of these Windows Surface 2 tablet/laptops but they only have 1 USB port… that or perhaps I’ll just suck it and buy another Vaio!? Choice choices. Anyone reading used a Microsoft Surface for any development work at all? Spice?, MPLAB?, anything besides email and browsing? Shoot me a reply or e-mail. Thanks!

Quick and dirty Hello World, PIC 16F1509 + 4 Bit 44780 format LCD

Okay… nothing magical here. Just a boring old “Hello World”. There doesn’t seem to be any sample code for the newer enhanced mid-range PICs with a LCD that I could find online; perhaps you can find something better with Google than I will.

I promise you two things with this code: It’s fresh off the press so it’s ugly, sloppy, poorly commented, I didn’t use pagesel at all, it’s probably buggy as sh%t and it’s slow. Remember 300 baud modems and BBS chat rooms? yeah…. déjà vu. I was having problems with timing and I don’t have a proper logic analyzer and I didn’t care to do all the math.. so I went safe. In fact after pasting the code I see a huge obvious flaw as it is, you’ll see it, but anyways it’ll display Hello World. Enjoy.

Full disclosure: I was heavily inspired by this code as a building block from piclist.. mostly I wanted a quick and dirty way to go 4 bit.

lcd_16f1509

;*******************************************************************************
; PIC 16F1509 LCD Test
; http://iradan.com
;
; ver 0.01 Hello World 4 bit, extra-dirty.
;
;*******************************************************************************
errorlevel -230, -302, -303
 LIST R=DEC
#include "p16f1509.inc"
 __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _CLKOUTEN_OFF
 __CONFIG _CONFIG2, _LVP_OFF & _STVREN_ON
;*******************************************************************************
;Device 16F1509
;
; PIN DIAGRAM
;
; RA0 O x RC0 O LCD_1/11
; RA1 I x RC1 O LCD_2/12
; RA2 I x RC2 O LCD_3/13
; RC3 O LCD_4/14
; RA4 O x RB4 I RC4 O LCD_E/6
; RA5 O x RB5 O x RC5 O ?FUTURE _ PWM?
; RB6 I RC6 O 
; RB7 I RC7 O LCD_RS/4
;
;*******************************************************************************
;
GPR_VAR UDATA
R_SEND_TMP RES 1
R_SEND_W_TMP RES 1
R_WDATA_TMP1 RES 1
R_WDATA_TMP2 RES 1
int_delay1 RES 1
;*******************************************************************************
; Reset Vector
;*******************************************************************************
RES_VECT CODE 0x0000 ; processor reset vector
 GOTO START ; go to beginning of program

;*******************************************************************************
; MAIN PROGRAM
;*******************************************************************************
MAIN_PROG CODE ; let linker place main program
banksel OSCCON
 movlw b'01111000' ; INTOSC 16MHz
 movwf OSCCON ;
 banksel OSCSTAT ;
 btfss OSCSTAT, HFIOFR ; Running?
 goto $-1 
 btfss OSCSTAT, HFIOFS ; Stable?
 goto $-1
goto START
;-------------------------------------------------------------
w_to_data
 BANKSEL PORTC
 movwf R_WDATA_TMP1
 movf PORTC, W
 movwf R_WDATA_TMP2
 bcf R_WDATA_TMP2, 0
 bcf R_WDATA_TMP2, 1
 bcf R_WDATA_TMP2, 2
 bcf R_WDATA_TMP2, 3
 btfsc R_WDATA_TMP1, 0
 bsf R_WDATA_TMP2, 0
 btfsc R_WDATA_TMP1, 1
 bsf R_WDATA_TMP2, 1
 btfsc R_WDATA_TMP1, 2
 bsf R_WDATA_TMP2, 2
 btfsc R_WDATA_TMP1, 3
 bsf R_WDATA_TMP2, 3
 movf R_WDATA_TMP2, W
 movwf PORTC
 return
pulse_e
 BANKSEL PORTC
 bsf PORTC,4
 call delay2
 BANKSEL PORTC
 bcf PORTC,4
 call delay2
 return
send_w
 movwf R_SEND_W_TMP
 swapf R_SEND_W_TMP, F
 movlw 0x0F
 andwf R_SEND_W_TMP, W
 call w_to_data
 call pulse_e
swapf R_SEND_W_TMP, F
 movlw 0x0F
 andwf R_SEND_W_TMP, W
 call w_to_data
 call pulse_e
 return
delay2
 BANKSEL int_delay1
 MOVLW 0x01
 MOVWF int_delay1
OLOOP
 BANKSEL TMR0
 CLRF TMR0
 BANKSEL INTCON
 BCF INTCON,T0IF
 MOVLW 0xC0 ; PortB pull-ups are disabled, (c3=1:16)
 MOVWF OPTION_REG ; Interrupt on rising edge of RB0
 ; Timer0 increment from internal clock
 ; with a prescaler of 1:4.
; The TMR0 interrupt is disabled, do polling on the overflow bit
T0_OVFL_WAIT2
 BTFSS INTCON, T0IF
 GOTO T0_OVFL_WAIT2
NOP
 BANKSEL int_delay1
 DECFSZ int_delay1,1
 GOTO OLOOP
 NOP
 ;... else
RETURN
START
BANKSEL PORTA
 CLRF LATA
 BANKSEL PORTB
 CLRF LATB
 BANKSEL PORTC
 CLRF LATC
 CLRF PORTC
 BANKSEL ANSELC ;
 CLRF ANSELC ;Digital IO
 BANKSEL PORTC ;
 CLRF PORTC
 BANKSEL TRISC ;Set all PORTC to outputs
 CLRF TRISC
 BSF PORTC,6

movlw b'11000111' ;configure TMR0
 BANKSEL OPTION_REG
 movwf OPTION_REG
; GOTO LOOP ;<--------------DEBUG
 BANKSEL PORTC
 bcf PORTC,7 ;LCD_RS
 movlw 0x02 ; Still in 8-bit, so appears as 0x20 to LCD
 call w_to_data
 call pulse_e
call delay2
movlw b'00101000'
 call send_w
movlw b'00001110'
 call send_w
movlw b'00000110'
 call send_w
call delay2
BANKSEL PORTC
 bcf PORTC,7 ; Command mode
; movlw b'00000010' ; Return cursor to home
; call send_w
 movlw 0x80
 call send_w
 BANKSEL PORTC
 bsf PORTC,7 ; Data mode
 call delay2 ; Takes a couple of ms
movlw 'H'
 call send_w
 movlw 'e'
 call send_w
 movlw 'l'
 call send_w
 movlw 'l'
 call send_w
 movlw 'o'
 call send_w
 movlw ' '
 call send_w
 movlw 'W'
 call send_w
 movlw 'o'
 call send_w
 movlw 'r'
 call send_w
 movlw 'l'
 call send_w
 movlw 'd'
 call send_w
 movlw '.'
 call send_w
LOOP
 ;
NOP
 BANKSEL PORTC
 BCF PORTC, 5
 call delay2
 BANKSEL PORTC
 BSF PORTC,5
 call delay2
 GOTO LOOP ; loop forever
END