Showing posts with label C18. Show all posts
Showing posts with label C18. Show all posts

Saturday, March 31, 2012

config vs config1 explained

Recently I started to use pic18f27j53 for a robot project. I picked it since it had USB functionality, and I thought I could learn about USB through it. Just as I copy-pasted my old code from my previous robot projects, error messages began to show up on the compiler output saying that opentimer1() was missing an argument. This confused me and, upon research, I discovered that many others were confused as well. So I decided to look through the source file (t1open.c) in the C18 library to see why there were two arguments (config and config1) as opposed to just one (config1).

Well, it turns out that some of the new microchip hardware has included some new functionality called Gate Control to the timer hardware, which introduces the possibility of controlling it through external asynchronous inputs such as the comparator module. This, I think, allows users to count the duration of an input.

Anyways, for those who do not intend to use the Gate Control Hardware, config1=0 should do the trick. Since config1 controls TxGCON (Timer X Gate Control), according to the datasheet, if you set config1 to zero Gate Control will be disabled.

Wednesday, April 6, 2011

LCD bug fixed

I have finally fixed the accuracy of my LCD code. Previously, my code contained many bugs, which essentially made the LCD unreliable. In fact, it was reliably dropping characters and ignoring commands. From the beginning, I had made sure that that I obeyed the timing diagram. However, I had completely forgotten to refer to the execution times listed by the instruction summary in the LCD driver datasheet. This means that I was sending instructions before the previous one completed.

I have finally implemented the proper delays allowing the commands to complete. Later, I use the busy flag or interrupt based display queue instead. 

Monday, July 6, 2009

PIC UART on 18f25k20

Due to my current job taking up all my time, I've had no time to work on my personal projects lately. However, I made use of my first 3-day Independence day weekend and figured out how to get serial UART working!

The truth is I couldn't figure out how to work the RS232 to USB stuff. So, I decided to take it slowly and try to figure out how to do UART first!

Here is the code: uart_practise.c

Although this was compiled using the C18 compiler, it can easily be modified to fit HI-TECH's PICC.

You will need some sort of terminal program to see the UART output. Also, if you don't have a serial port on your computer (as most people don't) you need a USB-Serial cable. Once you have everything hardware set up you need to set up the serial port as follows.
  • Baud rate: 9600 bits/s
  • Data bits: 8
  • Parity: None
  • Stop bits: 1
  • Flow Control: None
For more detailed directions and a circuit diagram visit: www.renomania.org/projects/uart.html


Sunday, April 26, 2009

USB to Serial using FT232RL

Recently I was able to obtain a FTDI USB to serial chip for free. I took this opportunity to integrate it into my LED dot matrix circuit. I am still wiring the thing up but I already got past soldering it on the SSOP to DIP converter board, which is the most difficult part of the setup. With my school  year at college coming to an end my workload has ramped up and so I am unable to work on my projects for more than an hour at a time. However, I intend to complete this before leaving for home for summer break. I am basing my circuit design off of the sample configuration given in the ft232rl datasheet so it shouldn't be too difficult, but I forsee trouble in interfacing it with the PIC. Using their C18 complier should make it easier. As with all of my other circuits I will be posting the code up.