Search This Blog

Thursday, December 16, 2010

Some Code - Bootloader, I2C, Maze Solving (virtual)

    Ok, time for some code updates.

    First up is the bootloader.  I rewrote my bootloader to accomodate my 16F877 and 16F876a chips.  Unfortunately, this meant the USART speed went down to 2400.  I didn't really notice much difference.  One thing I did put in my bootloader, a true erase sequence.  I made sure I wrote patch space ( 0x3FFF ) to every block from address 0x004 to the start of the bootloader code.  Yes, I know that the '877 and '876a do an erase before write, but what about old code that might sit in between your new code?  I opted for the safe route and made sure the space was clean.  It adds about 30 seconds to the '877's program time.  It adds about 10 seconds to the '876a.  I can live with it.  If you can't, just don't call the erase sequence.

You can download the assembly code for the 16F876a here. 
The adjusted Python code is here.

Note that the command line looks something like this now:
icsp.py /dev/ttyS0 16f876a 2400 /path/to/hex/file.hex -d
for program name, serial port, device type, baud rate, path to hex file, and -d debug switch.

    Next up is the test code I used to get the 32k eeprom working over I2C.  This is pretty much taken whole cloth from application note AN976 from Microchip.

Assembly code for I2C master mode with 32k eeprom.

    Last up is some test code I wrote.  It started as just a quick way to generate a graphical maze like those used for micromouse competitions.  I then patched in some maze-solving simulation.  It needs a total rewrite, but I still think it's cool and useful.

 Here is the maze code.

    And here is a screenshot of maze after solving:


    That's it for now.

No comments:

Post a Comment