Monday, March 24, 2008

Learning C Programming


I've decided to take up learning C for the AVR 8-bit microcontroller. Although I enjoy programming in ASM, larger scale projects require C programming. I suppose the LCD program was a wake up call as to how useful C programming is. I wanted to create a function in C that would output a string to the LCD display. Essentially I wanted to be able to type LCDPrint("Testing!"); and have "Testing!" appear on the display. After a few days working with C, I came up with a simple program that does just that. Arrays are fabulous for just this type of thing, and this was a great chance to learn the language.

Mr. Harrill, my electronics professor, has requested a project on outputting a keyboard to a LED display. I plan on interfacing the keyboard to an LCD display and then having that output go to the larger LED displays. This LCD program I made is the first step in that process. Since I don't want to have a large bundle of wires going to every LED controller or setting up extra hardware such as shift registers on the LED end, I need to work on doing USART communication between microcontrollers, and also interfacing with a keyboard. The keyboard seems to be quite easy, since I could probably setup an interrupt based system where it reads the bit value after each clock pulse. USART will be used simply because it's easy to use and is supported by nearly all AVR microcontrollers. I wish I had more time to work on all this, I barely had time to setup the LCD program. As stated earlier, classes, in this case macroeconomics, are crowding up my free time. Anyways, attached in this post is the program to interface with the 2x16 character LCD.

EDIT: Oh and did I mention I got a new job at the college?

LCD Interfacing Program: http://salgat.googlepages.com/LCDInterface.zip

Friday, March 7, 2008

Pictures and a Video of my Simple DVM Project

Today I took some pictures and a video of my DVM project. I really wish I had potentiometers to calibrate this thing, oh well, this is more of a learning project than anything else.


A picture of the DVM in action!




A view of the entire circuit, although the voltage dividers are kind of hidden behind the LCD display.




This video shows it in action. This circuit uses a ATmega644 microcontroller.


Attachments,
Picture of Assembler/Simulator: http://salgat.googlepages.com/simulation.JPG
Project Folder including Source Code: http://salgat.googlepages.com/AVRDVM.zip

Thursday, March 6, 2008

Updates on my Life

Just wrapped up a project I have been working on the past 2 mornings. I wanted to learn both ADC and the 2x16 character LCD, so I found a suitable project to incorporate them both, a simple DVM (digital voltmeter). The result is quite pleasing! In under 300 bytes I made a simplistic program that outputs "Voltage: XX.XV". The internal 2.56V reference isn't working for some reason, so I just used two 330 Ohm resistors in series to half 5V into 2.5V. If you take that along with the divide by 10 resistor network for the ADC input and the 10% tolerances of the resistors, it becomes understandable why it isn't perfect in accuracy (at lower voltages, the accuracy is within .1V, while at the upper limit around .8V). Since I knew anything beyond the tenths place wouldn't be close to accurate, I chose to use only 8-bit accuracy for the conversion. The program runs great and the display updates ~4 times per second (although this restriction is strictly aesthetic). The total cost of this high impedance DVM with decent accuracy is around $10, and higher accuracies will be obtained once I find more accurate resistors and fix the internal reference voltage problem.

I wish I could say that my devotion to my electronics is equivalent to my devotion to my school work. I have neglected all my school work this entire spring break, and now have 3 days left to play catch up. I hate to say hate, but I am absolutely sick of all my classes not related to my major electronics. Sociology, Business Management, and Economics in particular are becoming a nuisance. I find myself diverting almost all my attention from electronics to maintain my performance in those classes (although I do admit that I spend almost all my time on Friday-Sunday on Video Games, but that is to keep me sane through the rest of the week). As much as I love school, I dislike classes that while provide some life-long benefit, tend to be unnecessary. $1,400 and ~140 hours of my time going towards those classes, I hope that later in life they make up for their cost.

Another class that I have an aversion to is Visual Basic Programming. Although the class is neither required nor necessary by any means, I still decided to take it due to the many employers out there asking for experience with it. I absolutely enjoy programming in Assembly. The feeling of absolute control over what I am doing is amazing. My comparison between learning Assembly and learning Visual Basic is the difference between learning Math and English. I don't receive the same enjoyment from designing windows and programming in a manner where the computer does everything for me. I suppose it's the syntax that gets to me. Assembly on the AVR consists of 120 instructions. That's it, no more, no less. Visual Basic consists of thousands of different rules and instructions, all of which I have to learn. I have never liked English class, and I did poorly in my Intro to French Class. I am not surprised that I have a B in Visual Basic. I have found that the greatest challenge in taking 24 credits this semester is not the work, but the lack of interest. Last semester was heavenly, all electronics classes and a math class, which is why I could handle 23 credits with all A's. This semester however, I find it hard to find any interest in 5 of my classes. The possibility of several B's this semester is strong, but I'll probably drudge through it and increase my grades anyways. After all, I really would like a Scholarship or two for Lawrence Tech.