Friday, September 4, 2009

Travel - Part 5 - Rameswaram



So here I am at Rameswaram , the most memorable part of this whole journey.

We got down at the railway station at around 9 am and it was really hot at that time, we started walking to the end of the platform like everyone else. There was a sort of union of three wheelers, not to be bothered more we took one auto to be taken to the Ramanathswamy Temple. The auto dropped us near the temple and fortunately we got a balcony room with a wonderful view to the Temple. So after the 56hr journey , I got an opportunity to take a bath !!!!. We got our self all freshened up and then immediately set out for paying our regards to Ramanath Swamy. First we walked towards the Akniteertham, where I made my first contact with the holy sea of Rameswaram. But actually I was a bit disappointed, all through the way I had this image in my mind that i could really find a nice place to swim in the ocean here. But seeing the condition here I was sure that with all the people here taking a holy dip , this was definitely not a place to have a conventional swim in the water. After the holy dip we proceeded in the wet clothes itself towards the temple with the guide who was with us since the hotel. He lead us to the main temple where we paid for bathing in the 22 holy ponds.
One of the unique points of Rameswaram Temple are the 22 wells, each of these ponds is a fresh water well. It was a very different experience to feel the water from these wells , as a matter of fact the taste of water of all of them was different. It is a said that Ramji used water from these well to do Abhishek of Shivling. Some people believe that the water has medicinal value, who knows the combination of water and sun might be what it is believe to be. The way in the temple was bit confusing while going from one pond to another. As a matter of fact the corridor of Ramanathswamy Temple are one of the longest in the country. After the holy bath we had the darshan of Shivlinga as well as the Shivlinga brought by Hanumanji.

I would say that overall the Temple was not a beauty and I was a bit dissappointed when I say it at first. The very first impression on seeing the Temple Gopuram painted all in Yellow color was reducing the the beauty by a large factor. The picture of Meenakshi Temple of Madurai in mind made me assume that the Gopuram will be a piece of workmanship and it will be exquisitely decorated in all sort of colors. Inside also several panels, walls and pillars were unpainted. Though it is one of the CharDham tirth , the lack of beauty was a sore sight in the eyes. I hope that all these works get finished very soon and the temple stands above the Holy Shivling with all the grandeur and pride of Hinduism. Later we came back and had our Lunch at a local Marvadi Restaurant(Marvadi are residents of Rajasthan). I liked taking the food a fulfilling and tasty food after being feed up with Train Pantry Car food.
One very important thing that I did not mention, was that the moment that I say Ocean for the first time , I was longing to have a long and nice swim.(A swim is different from getting yourself wet , which is what I find most of the people doing in our country, I guess most don't know swimming and all they can do is to splash water on one another and jump over the waves !!! and this is what they call bathing in the Ocean). I was now a worried man , all through the visit in the temple I was thinking how could I salvage my situation. I was so determined to do scuba diving(which I had read that Rameswaram is a good place for) that I thought I would give a really hard try before giving up.


So just after our Lunch , I picked up my swimming costume and a towel and set out to what turned out to be a "real adventure". Before setting out for that , I tried asking my hotel guy is there is some place where I could do swimming or scuba diving. I tried hard to ask in a way that would make it sound that my intentions are very decent. But it did not help, the guy said in almost a sarcastic way that these things are not done in Rameswaram and for that you have to go to Chennai or Goa !!!. So I set out alone. The only thing I knew that on Wikimapia a location on the eastern side was marked as "Scuba diving" , so I got the impression that there might be someone who would rent out the snorkeling equipment. So for Agnitheertham I set out on foot to the north.(I remember I started from hotel at around 2 pm). So I was in Capri with a cap on my head , but without a water bottle and no watch or cell phone or a Digicam. So I kept walking on and on. After some distance I saw a foreigner coming from the opposite side, I thought that she might be knowing about the place I was seeking. She had also been trying to find a place to do snorkeling and it was also written in her guide book that it can be done here, she had walked on for about an hour, but found nothing. All she saw was that the fisherman were harvesting some kind of sea weeds and drying them up. It thanked her and started to start my own exploration. I was not happy about the situation that we don't even seem to have proper information dissemination mechanism in place , which could tell the tourists what attractions of the place are available. Soon the road turned away from the beach and so I came off the road and started walking on sand along the beach. It was there that I saw a building which was running some program of Microsoft in collaboration with TN govt. I was satisfied to find that atleast in some places poor people have some support from various agencies.

Well it is a known fact that it is much difficult to walk on sand than that on soil. This beach was rocky with sand in places and there were quite a few thorny bushes populating the beach. On top of it I was wearing sandals, so occasionally hot burning sand with a few minute thorns used to get into my feet and create problem in walking comfortably. Inspite of all this I just wanted to find that place to do scuba diving or to find that there is no such place like that at all. So I thought that I would go till the north most point of the island and then I will be convinced that no such place or facility actually exists. But I missed one point that the island was quite roundly shaped up in the north most point and I did not have compass and the sun was almost overhead , so it was not easy to estimate that you have reached the north most point. I had somehow assumed that when I had reached the north most point , I would be standing on a edge with land on my right and on my left. As I kept walking the water became cleaner and clearer. Now and then occupying a small portion of beach there were fishermen engaged in the activity of harvesting the sea weeds and drying them up. I was bemused to see the fishermen were a bit confused to see a stranger walking pass them. They might be thinking what does this guy what and where is he going to ? ( because they knew there in nothing special out there !!) I kept on walking on and on and mind you that too on sand, after some distance I would find that the beach would turn left and this kept on happening that the beach kept turning after I reached the end of one turn.
The small doubt that I had in my mind that there is really nothing out there so I have to decided sometime to turn back. As time passed several thoughts kept coming to my mind again and again. Some of them were absurd like if I was mugged by some of the locals( I am not a coward but , I could help just thinking about it !!!). Well to clarify nothing of that sort happened and I believe that such an endeavor are totally safe specially in broad day light. My mind was also working on possibilities like that what would happen if I would get dehydrated in this hot sun. These thoughts kept on becoming more and more prominent as I kept pushing forward.
After some point of time I was almost sure that I would not find what I was trying to find , but the driving force was that I should verify myself that if such place do not exist or not. I don't know how long I kept on going since I didn't have a watch on me. Though all through this I had been walking pretty briskly and that to at a constant pace, I was just not feeling tired, but the fear of dehydration was always on back of my mind. So at some place I finally decided that there has to be an end to every idiosyncrasy. I had really came a long way and I knew that it was not possible to go back along the beach itself. I had to get to some village and then find a way back to hotel and that too me being all in 1 piece. I rested in the serene water by wetting my feet for some time then I asked the nearest fisherman the way to city, he showed me the way, a path through thorny bushes.
Till the time i was along beach , i knew I could always walk back and find my way, but the way i was going could get me struck in no where. I kept walking on the marked path , but quite some time did not find even one person anywhere in sight. After walking for some distance I could see a long way away, the Doordarshan tower , but more importantly I also saw a temple on a hillock. I reasoned that in this town of temples , this one might lead me to some means of transport to get back to hotel, so I proceeded in that direction. But it still was a long way away but I had no choice and I kept walking and finally reached the Temple. It was often visited temple. It turned out that this temple was the highest point on this island and it is called Gandamadana Parvath. It is an excellent vantage point and it is said that Ramji took stock of his armies from this point and in the temple there was a foot impression of Ramji's feet in stone. It was only much later that I realized that I had actually walked about 1/3th of the island's coastline. It was easy to get a ride back to my hotel from there. By the time I reached the room, it was around 4:00 pm and all this trip or trekking took only two hours !!! Nonetheless I hit the sack and was deep asleep. I waked up again in two hours and we quickly decided that we will visit the 7 places of attraction in Rameswaram.
There are a lot of three-wheeler guys who easily offer a tour to all of these locations. So to ease our efforts we took one such three-wheeler with a deal to visit all these spots except Dhanushkodi. These places are the Sita, Hanuman Temples, temple with floating stones used in building the SethuSamundram Bridge to allow Ramji to reach Lanka. It hardly took 1 hr for these 5-6 places and we got an opportunity to visit the Ramanathswamy Temple once more. It was like getting lost in a maze, with the very long corridors and the temple dimly lit. Mother got an opportunity to do some shopping in the fancy shops in and around the temple selling lots of articles.

We waked up early the next morning and then quickly went to the Agnitheertham. I knew that we are supposed to do Manidarshan and then take bath and then the darshan of Ramanathswamy Temple. Somehow I assumed that Manidarshan meant seeing the Sun rising and it the first ray of Sun would be like a Mani or a pearl. We waited for quite long and the time kept passing and with nobody really taking a bath we got skeptical, so we now go to the Temple and we got to know that Manidarshan actually means the darshan of a sphatik-mani shivling in the Main temple.
So now a funny part was that, I has read quite clearly that there will be two lines for Mani Darshan, one of Rs 50 and other of Rs 15(something) and very surprisingly the Rs 15 line moves faster than Rs 50 line. I had this in mind but when we say both the line at the ticket counter we found more rush at Rs 15 line as compared to Rs 50 line. So I thought that maybe what I read was wrong and we purchased two Rs 50 tickets and quickly got into the Inner Sactorium, now here was the real deal, since lot of people like us had purchased Rs 50 ticket so there was a long line inside of that and a very short line of Rs 15. We being who we are, we got into the line of Rs 15 and even the ticket checker did not object. With this convenient arrangement, we had a very nice and relaxed Darshan as opposed to a rough treatment the Rs 50 ticket holder were receiving.
Next we went into Agnitheertham and I took a bath and since it was morning, so several energetic youths were enjoying themselves by actually swimming in the ocean. This was my first and as I understood as the Last opportunity to swim in the ocean on this trip, so I also took to the water. Now the reality hit me in the face. I was out of practice with swimming and it was almost a year since I had immersed myself in the pool, and all my dashing desire to go on swimming till I touch the horizon melted away in the vast expense of water within a few strokes. I was grasping for my breath :), so I did my best to satisfy these aquatic desire of mine !!!.

When I was done after about 30 mins, we again went to have a Darshan in the temple. It was nice to finally being able to get into the religious tranquility of the place.

After this we inquired about the bus to Madurai and the only one available left at around 2 pm , so we decided that there is still a lot of time, hence we checked out from our hotel and took a bus to visit Dhanuskodi. Dhanuskodi is about 18 Km from the city and we waited to board the bus to Dhanuskodi. The bus takes about 45 minutes to reach the last point of the motorable road. At this point there is a post with INDIAN NAVY written on it. And on this post there were a few soldiers manning it. At this point we found several jeeps which take tourist to the lands end. Well just to inquire about Dhanuskodi I went to one of the soldiers. HOLY COW !!!!! it turned out the guy was a MARCOS, who on earth would have thought that a very highly trained Indian Marine Commando will be posted on a distant place. It must be a really necessary and of course highly important task. Anyways I don't know what the commando saw , but he kind of presumed I was some officer or something !!!! :P.

We bargained a lot with the jeep guy and finally boarded the jeep. I took a vantage seat on top of the jeep, just before the jeep was about to leave the Navy Post, I tried to take a pic of the Post but the Marcos guy signaled a No. Nobody in there right frame of mind would like to cross their path with a Marcos guy on Duty , so I obliged and put away my cam.

Very soon the jeep was cruising on the sands rather than a metalled or paved road. So the story goes like this that several years back in around 1964 there was a big Tsunami which struck Rameswaram really hard. AT that time Dhanuskodi was a town with even a railway station. At that fateful night there was a train going towards Dhanuskodi Station and very tragically the train with all the occupants was washed away in the fury of nature. Not only this the whole town was washed away along with the Tsunami waves. The Pamban bridge also took a hit but due to some tireless engineering it was back in service within a record time. Since then nobody inhabited the old town again or neither the road or the rail link was restored again. So all the vehicles have to move over the sands to reach the end of land i.e. the last bit of Indian territory. The sand was really thick and the wheels of the jeep were leaving behind about 6 inches deep scars on sand. This piece of land was seemingly like a desert though surrounded on both sides by oceans. Far away we could see human figures like a very thin stick moving in this desert and even farther back in the north the TV tower was still visible though it became fainter and fainter as we moved ahead. Suddenly the jeep stopped and a middle aged women came out and walked towards a group of abandoned and ruined huts and buildings. Somebody told that she was a teacher and she comes here to teach the children who lives in these huts. I was so impressed that a person would actually come all the way here to nowhere and teach the children of fishermen so that they would actually become someone in their lives. The dedication of the teacher and all the people connected with this effort was worth saluting.

We went further ahead and now the two oceans started coming closer together as we forged our way ahead. Finally we reached our destination. We found a group of men doing some religious offerings. It was not actually a beach or land but technically they call it salt pans. We found it why, I went to wards the water and hardly had I stood for 5 seconds, I sinked till the knees. I just thought that if somebody just became unconscious while swimming then he would just be buried alive. The jeep was to stay for sometime and so I could not prevent myself from thinking about getting myself wet in the blue and serene water of the ocean. I quickly made good use of my Swimming costume and did a little splashing of water etc with the other guys on the jeep. It was a real fun and enjoyment as the water was so clean and cool. Most importantly this place was far away from the rush and madness of the normal tourists spots.
I had a brainwave at this time. It was a place which I knew , if I could I would definitely come back here. This place was idle from get away from the world. How would it be if a person could come here for a week in solitude and live here and reflect upon the Life. The placid surrounding , with the oceans on both ends and nobody really to disturb you, will definitely rejuvenate any wanting soul.

We got back again in the jeep and then the driver took us to a group of Huts belonging to the Fishermen who lives here. To our surprise there was a small Durga Temple present in which we presented offerings and sought the deity's blessings. I saw for a first time a Japanese well which was barely 50mts from the sea shore but the water was still sweet !!.

Then we returned back to the town on the same way by the bus. The entire journey took around 3hrs and after having our Lunch we waited for our Minibus to Madurai.

Thursday, August 27, 2009

Interfacing LCD with Microcontrollers

EMBEDDED HARDWARE DESIGN

Tutorial 2009-10/I

[This is a tutorial written for Embedded Hardware Design Course here at IIIT-Hyd]

LCD (Liquid Crystal Display) has become very popular option for displaying in Embedded Applications. Since they are very cheap and easy to interface with microcontrollers, they are widely found in devices like telephones, vending machines, washing machines, toys etc.

LCD comes in several varieties i.e. 16*2, 20*2, 20*4 etc. These different LCD varieties can display different number of characters i.e. 16*2 can display 32 characters at a time.

Introduction

The LCD module that we will be using is 16*2 JHD162A. This model has 2 lines and 16 rows of display blocks. Each block can be used to display 1 character. So there are total 32 such blocks. One block has 8*5 pixels. Depending on which pixel is ON and which is OFF we can display several Alpha-Numeric characters. This model also has a green backlight, which helps us to see the display even in dark. In reality this module consists of a controller chip, a segment driver chip, LCD display and some passive components.

There are total 16 pins in the LCD module.

Pin Number

Pin Name

Pin Function

Connection to ATMega16

1

Vss

GND Supply

2

Vcc

+5V LCD Power

3

Vee

Contrast Adjustment

4

RS

Register Signal Select(Command/Data)

PC7

5

R/W

Read/Write Select

PC6

6

E

Enable (read/write enable)

PC5

7

DB0

Data pin

-

8

DB1

Data pin

-

9

DB2

Data pin

-

10

DB3

Data pin

-

11

DB4

Data pin

PC0

12

DB5

Data pin

PC1

13

DB6

Data pin

PC2

14

DB7

Data pin

PC3

15

LED+

Backlight Power +5V

16

LED-

Backlight Power GND

These connections have already been made to the USB BootLoader Kit so when you insert the LCD module properly, the connections are made as mentioned in the Table.

While using LCD, we can think a simple analogy for its operation. Each of the 32 blocks is a memory, as soon as we write an ASCII number into one of these 32 memory locations the corresponding character is displayed on that block. The function of displaying the character after decoding the data is done by an onboard controller chip.

In reality the LCD module consists of several memory locations apart from the 32 dedicated for the display. Since LCD module can be used in several ways we need to select one of these modes and configure the LCD for this mode.

The various operations that we need to perform are:-

1. Write to LCD memory to display data

2. Configure LCD module by writing commands to memory location

3. Read data in Memory locations

4. Perform some special operations like Clear Screen , Bring Cursor to starting position etc

The various pins that are provided like RS, R/W etc acts as a way to do all these operations.The 3 control pins have important functions

1. RS The LCD has 2 modes of operation Character and Instruction. Depending on its value the data on the data line (DB0-DB7) is treated as either command or character. If RS is LOW then the data on DB0-DB7 is an Instruction and if RS is HIGH then data on data line is character

2. Enable – The pin acts like a clock for the LCD module, when there is a falling clock edge then the data on the data lines is taken in by the LCD module and processed.

3. R/W - This pin identifies if the operation to be performed is a read or write.

If R/W = 0 write operation R/W = 1 read operation

RS = 0 Command RS = 1 Character

E -> falling edge , data processed by LCD Module

To be able to correctly perform an operation we have to assign the values of these 3 control pins and data lines in a proper sequence.

Let’s look at one example i.e. displaying a character by writing to its memory location. The steps are:-

1. Set the data on the data lines i.e. the 8 bits of data are assigned to each of the 8 pins (DB0-DB7) like LSB -> DB0 and MSB ->DB7.

2. Set RS pin i.e. make RS pin HIGH.

3. Clear RW pin i.e. make RW pin LOW.

4. Toggle E i.e. make E high, wait for some time, make E low.

Another example, if we want to write a command, the steps are:-

1. Set command on the data lines i.e. the 8 bits of data are assigned to each of the 8 pins (DB0-DB7) like LSB -> DB0 and MSB ->DB7.

2. Clear RS pin i.e. make RS pin LOW.

3. Clear RW pin i.e. make RW pin LOW.

4. Toggle E pin i.e. make E high, wait for some time, make E low.

A very important point to note is that the sequence of these steps can be done manually using toggle switches only and the microcontroller is only used because the repetitive steps need not be performed manually again and again.

In the above examples we used 8 data pins and 3 pins for control signal i.e. total 11 pins of the microcontrollers are used. An efficient way is to use 4 data pins instead of 8. In case we are using 4 data lines , the higher nibble is send on these 4 data lines first and then we send the lower nibble on the 4 data lines. In this case we are using 7 lines of the microcontroller. This mode is called the 4-bit transfer mode. By default when we are using 4-bit mode the data transfer happens only through DB4-DB7 (the LCD pins) whereas DB0-DB3 are unconnected.

In the datasheet of LCD module we find a table shown below. This is the Instruction set of the LCD Module JHD 162A.

Let’s look at first row - SCREEN CLEAR. This Instruction tells the LCD module to return the cursor to the starting position i.e. (1, 1) and also to clear the screen of any characters. The code for this instruction is 0x01. If we want the LCD module to clear the screen, then we should write the command 0x01 to the LCD Module.

Similarly we have DISPLAY SWITCH instruction. It selects options for the display like Turning the display on/off, turning the cursor on/off, turn blinking of cursor on/off.

If we want to turn display on we set D (DB2) to 1, to turn cursor on we make C (DB1) 1 and to select blinking cursor B (DB0) is set to 1. Hence the final code of Display switch is 0x0F.

If we write a command 0x0F, then the LCD module will perform the above mentioned 3 actions.

Finally we will look at FUNCTION SET- this Instruction selects the 4-bit/8-bit mode (DL =0 means 4-bit transfer mode selected whereas DL=1 means 8-bit mode selected), N selects the number of lines in LCD (N=1 means a 2-line display), F select font type (in our case we have 5*7 type font which means F=0).

Hence to select a 4-bit mode, 2-line display and 5*7 font the value of FUNCTION SET becomes 0x28.

If Instruction INPUT SET is not given then by default after every character write, the cursor moved to next block. [But this does not implies that after writing to (16, 1) the cursor will automatically come to (1, 2)!!! you will have to set the address of cursor to (1,2) yourself.]

Instruction Set of LCD Module

0x80

0x81

0x82

0x83

0x8D

0x8E

0x8F

0xC0

0xC1

0xC2

0xCD

0xCE

0xCF

Memory Address of Display Block on the LCD Module


The Memory addresses of blocks on LCD display are as shown above. So if you send a Command say 0x80, then the cursor will reach to the first block i.e. (1,1) similarly if you send a command 0xC5, then cursor will reach location (5,2) and so on. In this way you can move cursor to any position.

To make the LCD work with microcontroller you will proceed in this way:-

1. All the functions of the LCD will be written in a separate file named lcd.h, so that whenever you need to use the LCD functionalities, you will just include this header file lcd.h, and call the functions written in lcd.h to display or configure LCD module.

2. In the lcd.h you should have the following functions:-

(a) LCD_init(void)

(b) LCD_Send(char c, unsigned char DC)

(c) LCD_Send_String(char *s)

(d) LCD_GotoXY(unsigned int x, unsigned int y)

(e) LCD_Print(int data, unsigned int x, unsigned int y)

LCD_init – This function initializes the LCD module by setting 4-bit data transfer mode, turning the display on, turning the cursor on and setting the cursor to blink.

LCD_Send – This function takes two arguments c, DC. Here c is the data which we want to write and DC identifies this data to be a command or character (data) i.e.

if DC=1 => Data

if DC=0 => Command

LCD_Send_String – This function takes a string as input and after parsing it ,send character by character to LCD_Send() function , to print the character on by one on the display.

LCD_GotoXY – This function takes the cursor to position (X, Y) in the display.

LCD_Print – This function takes 3 argument i.e. data (a numeric value), and x, y co-ordinate of the starting position of the printing of the data. First this function calls LCD_GotoXY to move cursor to (x, y). Then the function calls itoa() function and send the resultant string to LCD_Send_String().

The Pseudo code of the functions are written as follows:-

LCD_init(void)

{

Clear RS pin, clear RW pin.

Write a command to clear the screen

Write a command to turn display on, turn cursor on, turn blinking of cursor on.

Write a command to select 4-bit mode, 2 line display, 5*7 font.

}

// when we say write a command it means that the function LCD_Send is called.

LCD_Send(char c, unsigned char DC)

{

Break the 8 bit value of char c into 2 parts, upper nibble and lower nibble.

If it is command

Write upper nibble on data line

Clear RS pin, clear RW pin

Toggle E pin, put some delay (~1ms)

Write lower nibble on data line

Clear RS, clear RW pin

Toggle E pin, put some delay (~1ms)

If it is Data

Write upper nibble on data line

Set RS pin, Clear RW pin

Toggle E pin, put some delay (~1ms)

Write lower nibble on data line

Set RS pin, Clear RW pin

Toggle E pin, put some delay (~1ms)

}

// you will need to put delay while toggling E i.e. Set E, put 1 ms delay, Clear E.

LCD_Send_String(char *s)

{

Break string s into characters, say c1, c2, c3…

LCD_Send(c1), LCD_Send(c2), …..

}

LCD_GotoXY(unsigned int x, unsigned int y)

{

If it is line 1, send the command corresponding to address of 1st line.

If it is line 2, send the command corresponding to address of 2nd line

}

LCD_Print(int data, unsigned int x, unsigned int y)

{

Call LCD_GotoXY(x,y)

Break integer data into character and call LCD_Send_String().

}