Today , I begin a series of posts that will involve the things I hold dear – Sanskrit and Science.
Presenting , xkcd संस्कृतभाषायाम् !
पश्यन्तु , आनन्दम् अनुभवन्तु !
Pre – IISc :
ε> – Love
Post- IISc :
ε> – Epsilon greater than
They say love means different things at different ages.
I’m disappointed to know this what they meant.
Programming AVR MCUs in C
I am starting to write a series of tutorials on programming AVR uCs in C. I plan to write articles covering Interrupts , ADC , timers , internal EEPROM, PWM and USART. This is the first in those series and it covers basic I/O operations. Here is the link to the page.
I finally dug out that LCD from the mess in my room and got it to work . Turns out , its really simple. You dont even need a microcontroller to do it.
Ok. Lets get started :
That is the LCD that i bought from SP road (kwality electronics) for 100 bucks. It incorporates the widely popular HD44780 pin configuration. It has 16 pins.
This is how it looks from the back :
There are 16 pins in all. They are numbered from left to right 1 to 16 (if you are reading from the backside) . My LCD came with a marking to indicate which was the 1st pin and which was the 16th. You can see the markings right next to 1st and 16th pins.
The LCD is
I took the back view pic after I soldered a 8 pin connector between the 7 to 14 pins to make it easier to work with. When you buy the LCD ,all the pins will be bare. ( like in the first pic).
Did you notice that there is a fine film covering the LCD display in the first pic? DON’T remove it until you finish soldering wires and connectors to the pins. Otherwise ,the flux and the alcohol that you use during the soldering process will ruin the LCD.
These are the functions of the 16 pins :
- VCC (+5V)
- Contrast adjustment
- Register Select (R/S)
- Read/Write (R/W)
- Clock (Enable)
- Bit 0
- Bit 1
- Bit 2
- Bit 3
- Bit 4
- Bit 5
- Bit 6
- Bit 7
- Backlight positive power rail
- Backlight negative power rail
Pin 1 and 2 are the power supply pins. They need to be connected to the negative rail and the postive rail of a +5v power supply respectively. To get a stable +5v Power supply , you can use a 7805 voltage regulator. It will regulate any voltage that you give it into +5v. If you are confused about using the 7805 , check out this tutorial.
Pin 3 is the contrast setting pin. It must be connected to ground in series with a 5K pot. The lower the resistance , the greater the contrast. I recommend setting it at around 1.5K – 2K. If you set the value too low or short the pin directly to ground , you will see only dark boxes on the screen. As far as i know , doing this does not have any adverse affect on the LCD.
Pins 4 , 5 and 6 are control pins of the LCD. I’ll explain about them later on in the post.
Pins 7 to 14 are the Data pins of the LCD. Pin 7 is the Least Significant Bit (LSB) and pin 14 is the Most Significant Bit (MSB) of the data inputs. If you want to display some number or letter on the display , you have to input the appropriate ‘codes’ for that character on these pins. These pins are also used for giving certain commands to the display like clearing the display or moving the cursor to a different location. Upon giving the correct signals to the 3 control pins , the character codes or the commands that you have given to the Data pins will be written to the display or executed by the LCD respectively. To make it easier to give the appropriate inputs to these pins , i recommend wiring up a DIP switch to these pins.
Most LCDs have a backlight. A backlight is a light within the LCD panel which makes seeing the chracters on screen easier. When you leave your cell phone or mp3 player untouched for sometime , the screen goes ‘dark’. That is the backlight turning off. It is possible to use the LCD without the backlight as well. Many LCDs come without a backlight. If your LCD has only 14 pins , then it has no backlight. However , the working of the LCD still remains the same even if your LCD doesnt have a backlight. The Backlight is nothing but an LED. So , a resistor must be connected in series with it to limit the current. I am not sure about what value of resistor must be used. This link mentions that the allowable current is 100ma. Then it is best to have a variable resistor (or a transistor) and adjust the current till it is around 90 ma.
Now for the important part : The 3 control pins : R/S , R/W and E
The LCD has basically two operating modes : Instruction mode and Data Mode
You have to activate the command mode if you want to give a Instruction to the LCD. Example - “Clear the display” , “Move cursor to home” etc.
You have to activate the Data mode if you want to tell the LCD to display some character.
To set the LCD in Instruction mode , you set the 4th pin of the LCD (R/S) to GND. To put it in data mode , you connect it to Vcc.
The enable pin has a very simple function. It is just the clock input for the LCD. The LCD will perform whatever function you want it to do on the falling edge of the enable pin.
Generally , we always use the LCD to show things on the screen. However , in some rare cases , we may need to read from the LCD what it is displaying. In such cases, the R/W pin is used. However , this function is beyond the scope of post and will not be explained. For all practical purposes , the R/W pin has to be permanently connected to GND.
So this the flowchart for operating the LCD
1) Set the LCD in either Instruction mode or Data mode depending on your requirement.
2) Give the appropriate codes at the Data pins for the function that you wish to perform.
3) Give a short pulse at the Enable Pin from positive to negative and back to positive again.
4) Voila , your instruction will have been executed/ Data shown on LCD
5) Go back to 1
Ok. Now that you have understood this , before starting , it would be more convenient if you soldered together a board with connectors and buttons for controlling all the pins.
Here’s the circuit :
Here’s a quick review :
1) Goes to GND as it is a power supply pin.
2) Goes to +5v as it is a power supply pin.
3)VEE – contrast adjustment. Connect this to GND along with a series resistor of 2K.
4) RS – Register select. – You can use this to select between the instruction mode and data mode of the LC. Depending on the status of this pin , the data on the 8 data pins (D0-D7) is treated as either an instruction or as character data.
There are 2 possibilites :
Switch Open : The pull up resistor holds the RS pin at Vcc. Data Mode is activated as RS = 1
Switch Closed : The RS pin becomes a part of the ground. Instruction Mode is activated as RS =0
5) RW - Permantently connect this to GND.
6) Enable – The instruction or the character data at the data pins (D0-D7) is processed by the LCD on the falling edge of this pin. The Enable pin is normally held at Vcc by the pull up resistor. When the momentary button switch is pressed , the Pin goes low and back to high again when you leave the switch.
Your instruction or data will be executed on the falling edge of the pulse. (ie. The moment the switch closes)
7-14) Data pins – This is where you give the LCD the ‘codes’ for any instruction or character.
Its not very convenient to have 8 wires and try to make them HIGH or LOW on breadboard. Hence , i recommend that you use a DIP switch along with 8 pin SIP connectors. This is the thing that i made for the job :
The circuit is very simple and you need only 8 pull down resistors (1K) to make the circuit. You can even use a SIP resistor pack to save space and soldering time.
I have mounted the DIP switch on quite a large PCB. You can make a small one if you want to conserve space.
Download the PCB files from here and make your own DIP switch board.
Join together two female connectors to make a female-female connector. Solder a male connector on the LCD data pins.
Now that you are ready with the supporting hardware, lets get started with the real stuff.
But first , before powering up the LCD , double check all these things.
1) No pins are shorting on the backside of the panel. (It can happen if you have not cleaned the board after soldering)
2) The contrast pin (3) (Vee) is connected to GND in series with a resistor
3) The backlight (pins 15 , 16) has a resistor in series to limit current.
4) The DIP switch board is working properly.
5) The R/W pin is tied to ground.
6) The circuit is being powered by +5v. This is very important. Dont zap your LCD by accidentally powering it with 12V.
7) The connector for connecting the 8 data pins from the DIP switch board to the LCD is proper. Double check for any loose wires and any mismatched wires on the connector.
If you are sure that nothing is wrong with your setup , then go ahead and power up you LCD.
See nothing at all on the LCD? Dont panic. Thats what is supposed to happen.
To make the LCD first show some signs of life , you need to issue an instruction to it. That instruction is 00001111. Since you are giving an instruction to the LCD , you have to put it in instruction mode by holding the RS pin to GND. In the board that you wired up, you can put RS at GND by pressing the RS pushbutton such that it remains in a depressed state.
Now , your LCD is in instruction mode and is ready to accept any instruction that we issue to it. Now , set the DIP switches as 00001111. This instruction tells it to turn on the display and show a blinking cursor. Once , you have set the DIP switch to 00001111 , press the Enable Button once and leave. You should be seeing a blinking cursor on the screen now. This means that your LCD is initialized and ready to accept characters to display.
Wait , you did not get a blinking cursor? Triple check if your connectors and switches are proper. Check if you have accidentally reversed the MSBs and LSBs on each side of the connector. Check your soldering to see if there are any cold solder joints.
Ok , once you have got the cursor blinking , the LCD will now accept character data to display. Now , we have to put the LCD in character mode to make it accept characters to display. Press the RS switch to make it ‘undepressed’. Now set the DIP switches to 01000001 and then press the Enable button. If everything has gone right , then you should be seeing a capital A on the screen. But what if you want to display some other letter , like “M”? The procedure is the same , you only replace the 01000001 with the code for M , which is 01001101. Try the same thing for “M” , M will appear next to A. You can totally write 16 characters in each row of the LCD. You would expect the 17th letter to appear at the 1st block of the 2nd row. However , this is not the case. For some silly reason , you have to do somemore things before that can happen. I’m pretty much bored of typing now , so i’m going to end this tutorial now.,
When the LCD starts , you have to initialize it first. That means that you have to give a certain instruction to it to make it work properly.
The initilizing instruction is 00001111.
Since it is an instruction , set the LCD in instruction mode by setting R/S to GND.
Then give the instruction code (00001111) at the data pins.
Then give a short pulse at the enable pin.
You should now be seeing a blinking cursor.
While taking a trip down the memory lane , I stumbled upon this picture of my ”Cotton Candy Contraption” that I built two years ago. It was made from a motor that I extracted from my cousin’s toy car and a Tin can punched with holes. And it really did work!
The first question that comes to your mind :
What is an EEPROM?
To cut it short , EEPROM is a memory device , similar to the memory stick in your cell phone or camera.
The Pin layout of an EEPROM is very similar for most Static RAMS. So once you know how to program an EEPROM , you also know how to program RAM.
So lets get started.
Before knowing how to use an EEPROM , you have to know how it organizes its data.
The EEPROM is divided into 8912 “houses” with eight rooms in each house. You are allowed to store either a 1 or 0 in each room.
When you wish to write some data to the EEPROM , you have to specify the address of the “house” where you want to store your data.
(Did you ask yourself why the number of “houses” is something as arbitary as 8912? Its because 2^13 is 8912. And there are 13 Address choose pins on the IC.)
Then , using 8 input pins , you have to give 8 values which will be stored in the eight “rooms” of selected “house”.
The procedure is very similar when you want to read the data back.
Again , you will have to select the address of the “house” and the 8 values in the eight rooms will appear through the output pins.
If add up the total number of pins : 8 for input +8 for output + 2 for power + 13 for address + 3 control pins
= 34 pins!!!
So to reduce pin count , Manufacturers have combined the Input and Output pins and made them into a single set of 8 I/O pins. This makes it a bit tougher to use the IC as both the functions have to be done by the same set of pins.
The Procedure :
EEPROMs have 3 control pins : CE (Chip Enable) , WE (Write Enable) , OE (Output Enable)
This truth table should make it pretty clear how the 3 pins work :
|0||1||1||Outputs are Tristated|
|1||0||0||Chip Disabled – Outputs are Tristated|
|1||0||1||Chip Disabled – Outputs are Tristated|
|1||1||0||Chip Disabled – Outputs are Tristated|
|1||1||1||Chip Disabled – Outputs are Tristated|
Here’s the explanation :
The Chip can Read/Write only when CE is low. If CE is held high , then the chip is disabled and the I/O pins are tristated.
When CE is LOW, OE is low and WE is held high , the data in the memory location chosen by the address pins , appears at the I/O pins.
On a new EEPROM which has never been programmed before , all the memory locations are programmed with 1′s by default. So , while reading from a new EEPROM , you will see only 1′s in every memory location.
To write , input the 8 bits that you wish to write at the I/O pins while holding OE high and WE low. Then raise WE to high and then back to low again. Then , the data that you have given on the I/O pins will be written on the rising edge of the pulse to the address that is present on the address pins at the rising edge.
The waveform will be like this :
So , if you have not understood from the above waveform , let me make it very clear.
This is the way to manually write to an EEPROM :
1) Hold OE and CE low and WE high – Read Mode – Whatever is in the location determined by the address pins will appear at the I/O pins.
2)Hold CE Low, OE high and WE high – I/O pins are tristated – disconnect the output leds (or whatever) from the I/O ports
3)Hold CE low , OE high and WE low – Write Mode – Give the data to be written at the I/O port and the address where you want it to be written at the address pins.
4)Hold Ce low ,OE high and WE High – I/O pins are tristated AND data is written – Disconnect the Switches or wires that you used to give data to the I/O port.
5) Hold CE and OE Low and WE high – Read Mode – You are back to step 1. Whatever is in the location determined by the address pins will appear at the I/O pins.
The procedure is same for RAMs as well. The only difference between EEPROMs and RAMs is that RAMs lose whatever has been written when the power is turned off , but EEPROMs dont.
There are many EEPROM and RAM ICs available. The EEPROM that i generally use is AT28C64B from Atmel. It is available at around 100 INR (~2$) here in bangalore. The cheapest RAM IC is 6264 which is available for 35 INR (0.7$)
The writing procedure that i have described above is rather crude. There are better ways of writing to the same EEPROM. But , this is best way if you are using the EEPROM by giving CE ,WE, OE signals by hand.
I finally finished collecting the next 150 data sheets (74150-74300) yesterday. Here are the links to the data sheets :
Set 2 – 74150 to 74300
Set 1 7400 to 74150
Here “trimmed” means that I’ve edited the pdfs and have removed all the crap like ” IC Physical Dimensions “, which we never use.
I have the unedited pdfs with me. I couldnt upload them as 110mb.com (where i store my files) has a cap of 8mb per file.
If anyone wants the unedited collection , please email me at firstname.lastname@example.org or leave a comment. I will be more than happy to email it to you.
I was getting frustrated of dashing to the computer everytime to refer to a datasheet. So , I’ve decided to make a collection of all 7400 series data sheets and print it into a book. I have uploaded the first set that i have collected – from 7400 – 74150. I hope it will be of use to someone.
PS : I have trimmed the datasheets and uploaded only the first one or two pages of each which really contain most of the important stuff.
The Links :
Despite searching on every datasheet search engine , i could not find the datasheets for these ICs :
If anyone has any of these datasheets , please do email it to me at email@example.com i will definitely update the post.
After much patient effort and wasting many dozens of PCB s , i finally learnt the art of making pcbs the right way.
Here are the steps , so that you don’t have to undergo the grind that i had to :
1) Clean your PCB thoroughly.
Rub it vigorously with sandpaper both vertically and horizontally.
Then using some steel wool and a dish washing soap (such as Vim) , clean the PCB thoroughly.
Then dry the PCB using some tissues. Immediately after this , clean the PCB one final time using tissues and acetone. I have found that although alcohol works too , the success rate is much higher with acetone.
All this is done so that the PCB is clean and free of any dust or grease which repels toner. Make sure that you never touch the PCB directly during any point of time. The thin film of oil on your hands will stick to the PCB and will prevent the toner from adhering properly.
Also do not leave the PCB for more than 10 minutes after cleaning. Dust may resettle on it. I learnt this the hard way. Remember that every step is important and the PCB will almost definitely not come out right even if you miss a single step.
A word of caution : Do not use the steel wool that you used for any other purpose. Copper particles aren’t too good for health.
2) Preparing for Toner Transfer
This involves printing out your circuit design (though a Laser printer ONLY) on an OHP sheet and then taping it on a PCB and ironing on top of it. This will cause the toner to melt and get transferred onto the PCB. This is the most delicate and most crucial part in PCB making.
a) Design and print out your circuit using a software such as EAGLE or Express PCB on an OHP sheet using a Laser printer. I personally prefer ExpressPCB. Remember that your design will be inverted when it is transferred onto the PCB.
b) Cut the design to the appropriate size and lay it down on the PCB such that the cutout holds to the PCB by means of a ” Suction Lock “.
Then tape it to the PCB , making sure that there are no air gaps ( this is extremely crucial). I have found that the tape that works best is Painters Tape which is available at any hardware store. It is best if you can get tape of width ~ 1 inch ( shown in the pic on left).
3) The actual Toner Transfer
Using an electric Iron set to it highest setting (with the water removed ,please) press on the PCB with the largest force that you can muster for around 20 seconds.
If have taped the cutout properly , then the cutout should neither wrinkle nor blacken due to the heat. Using the tip of the Iron , carefully run over the traces a few times to fix them in place.
After doing this , once again press on the PCB for around 10 seconds. Make sure that at no point of time the traces get smudged or merge together.
At this point you must be able to visually see that the toner has melted. If you feel that the toner has not melted completely in a few places , then feel free to run them over using the tip of the Iron.
Now immediately take the PCB and dunk it in a container full of tap water. This will cause the toner to become solid and stick to the PCB. Leave in the water for atleast 15-20 seconds.
Then remove it from the water and slowly peel off the tape and remove the cutout. Atleast 95% of the toner must have transferred to the PCB.
here is a video which i made to show you how exactly it is done :
However , note from the video that a single pad hasn’t transferred from the sheet to the PCB.
To fix this , just use a permanent marker (blue or black) and just draw over the place where the pad should be several times (this is very important) . The permanent marker will act just like the missing toner.
4) The final part – Etching the PCB
This involves dunking the PCB in a tub full of a chemical that can dissolve copper. Some typical example are ferric chloride , ammonium persulfate , and a mixture of HCL and 3H% H2O2.
Ferric Chloride is most commonly available in india. To prepare the etchant using HCL and H2O2 , refer this link. Ammonium persulfate is said to be better than FeCl2 as the soultion is clear and hence you can overlook the etching process.
The etchant prepared from HCL and H2O2 is faster than FeCl2 , but unfortunately it also dissolves permanent marker ink. So , there is no chance of making any corrections on PCBs after you perform toner transfer. This is the primary reason why i am sticking with FeCl2.
Warning : If you are using FeCl2 , let me tell you that it stains anything , including skin upon contact. The stains are nearly impossible to remove. If you get FeCl2 on your skin , wash it off immediately using water.
Ferric chloride is available in the form of dry (and rather messy) power. The instructions say to dissolve 500g of the powder in 1 liter of water. I have found that dissolving around 700g makes a more potent solution.
After you prepare the , dunk the PCB in it and leave it for a while. At room temperature and with no heating or agitation , it takes around 4 hours to complete. With heating , it (reportedly) reduces to 1 hour. I have never tried heating myself so i really dont know much.
UPDATE : I bought a new 500g FeCl2 pack and dissolved it in 500ml of water ( The recommended amount is 1 liter). And i heated it by placing the container full of FeCl2 in another tub full of hot water. Amazingly , it finished etching in just 10-15 mins!!
I don’t know what had such a major impact on the etching time ; Was it the heating or was it the more concentrated solution??
Use ONLY PLASTIC TWEEZERS to remove the PCB from the etching solution. After it is done , clean the PCB thoroughly with water and soap. To remove the the toner , use either sandpaper or acetone.
And voila…You’re done…
Note : Always remember to sand the PCB once before soldering , as the oxidized copper will repel solder.