Friday, May 23, 2008

PIC Clock

Finally I managed to build the initial version of the Desktop clock using PIC16F84. Still its in the vero board as you see in below video.



It shows Time (Hour, Minute) and Seconds alternatively. It has two buttons to advance hours and minutes. An Interrupt routine is used to calculate the base time and to multiplex the four seven segments. The program is written in C and compiled using MikroC compiler. I got lot of ideas from so many people and used code samples from various resources. Specially the MikroC comes with very useful code samples. Here is the program listing. It is not optimized yet. You'll find unused variables here and there. Comments and suggestions are welcome.


#include "Display_utils.h"

char kraj;
unsigned short zz, v, j, countsec,displaysec;
//unsigned int i;
unsigned short por[4];

unsigned char sec, mins, hrs, ticks, correction;
char oldstate_min, oldstate_hr;


void interrupt() {

if(INTCON.T0IF)
{
ticks++;
correction++;
TMR0=101; //96; //102

if (correction==180) // Correction routine
{
ticks--;
correction=0;
}
}



PORTA = ~0;
PORTB = por[v];
PORTA = ~zz; // turn on appropriate 7seg. display
zz <<= 1;
if (zz > 8u)
zz = 1; // prepare mask for digit

v++ ;
if (v > 3u)
v = 0; // turn on 1st, turn off 2nd 7seg.
//Delay_ms(1);
//TMR0 = 0;
INTCON = 0x20;
}//~

void main() {
OPTION_REG = 0x84;
j = 0;
v = 0;
zz = 1;
TMR0 = 101;
INTCON = 0xA0; // Disable PEIE,INTE,RBIE,T0IE
PORTA = ~0;
TRISA = 0;
PORTB = 0;
TRISB = 0;
sec=0;
mins=0;
ticks=0;
correction=0;
hrs=0;
oldstate_min=0;
oldstate_hr=0;


do {

if (ticks==200)
{
sec++;
countsec++;
ticks=0;

//if (PORTB.F7==1)
// {
// PORTB.F7=1;
// }
// else
// {
// PORTB.F7=0;
// }
//}
if (sec>59)
{
mins++;
sec=0;

//}

if (mins>59)
{
hrs++;
mins=0;
//}


if (hrs>23)
{
hrs=0;
}

}
}
}
TRISB=0b00000011;
if (Button(&PORTB, 0, 1, 1))
oldstate_min = 1;
if (oldstate_min && Button(&PORTB, 0, 1, 0)) {
mins++;
if (mins>59)
mins=0;
oldstate_min = 0;
}
if (Button(&PORTB, 1, 1, 1))
oldstate_hr = 1;
if (oldstate_hr && Button(&PORTB, 1, 1, 0)) {
hrs++;
if (hrs>23)
hrs=0;
oldstate_hr = 0;
}

TRISB=0b00000000;



if (countsec==5)
{
countsec=0;
if (displaysec==1)
{
displaysec=0;
}
else
{
displaysec=1;
}
}


if (displaysec==0)
{
por[0]=mask(hrs/10u);
j=(char)(hrs%10u);
por[1]=mask(j);

por[3]=mask(mins/10u);
j=(char)(mins%10u);
por[2]=mask(j);
}
else
{
por[0]=mask(5);
//j=(char)(mins%10u);
por[1]=mask(11);

por[3]=mask(sec/10u);
j=(char)(sec%10u);
por[2]=mask(j);
}


} while(1); // endless loop
}//~




Display_utils.h file


//-------------- Returns mask for common cathode 7-seg. display
unsigned short mask(unsigned short num) {
switch (num) {
case 0 : return 0x3F;
case 1 : return 0x06;
case 2 : return 0x5B;
case 3 : return 0x4F;
case 4 : return 0x66;
case 5 : return 0x6D;
case 6 : return 0x7D;
case 7 : return 0x07;
case 8 : return 0x7F;
case 9 : return 0x6F;
case 11 : return 0x79;
} //case end
}//~

Thursday, February 21, 2008

PIC Programming

Programming a micro controller has been in my mind for nearly a decade. I have done micro controller programming when I was an under graduate. That was for the 8080 processor. It is too big for small projects. I was looking for a suitable type of micro since there are couple of good ones PICs and AVRs. But I couldn't find any AVRs in the market but PICs are available for an affordable price. I bought two PICs, 16F877A and 16F84A, for Rs. 460/- and Rs. 320/- respectively.

The first step was to build a programmer (burner). I saw different types of programmers but thought of building a JDM type one. It has the advantage of operating without an external power supply and is much simpler to build. It takes power from the PC serial port. The disadvantage is, modern laptops cannot provide the required voltage level. Since most of the laptops (including mine) do not have a serial port, it has no effect.

Found the following circuit and built it on a vero board. It can program PICs upto 40 pins so there wont be any problem for a long time. (Full credit goes to the designer of the circuit, I just build his circuit)



This is how the final one looks like;



Then needed the software to connect the hardware to the PC. After reading many comments, I wanted to settle with IC-Prog. It is a great software which supports many types of programmers including the JDM. It also has a hardware test option to verify the hardware. Initially it didn't verify my hardware correctly and after so many sleepless nights, I found the bug. I have connected the Serial port incorrectly; more precisely, I have swapped the left hand side and the right hand side of the port. After rearranging, it worked like a charm.

I tested the programmer and the PIC using the famous "hello world" LED blinking program which ended quite successfully. Then I wrote a counting program using two seven segment LEDs with 16F84. Two segments are in multiplexed mode. The following video shows it in action.



These are my future plans with PICs.

- Build a clock with small digits (desktop clock)
- Build a wall clock with a big display
- Include the stealth mode to the clocks. i.e. it will retain its time when there is no mains power. I hope to use a real time clock IC like DS1307 or DS1302 with a battery backup.
- Include a thermometer function to the clock to display the room temperature. For this, I will use DS1820 IC.

Although I already have necessary hardware i.e PICs, clock ICs, temperature ICs (I got them from Dallas Semiconductors as samples), writing software takes a lot of time. Therefore it is impossible to figure out how long it will take to complete the above things. May be before next Christmas... :-)

Thursday, November 08, 2007

Hi...

Well, it's more than 6 months after my last post. Few things kept me away from blogging;
MBA - which is almost finished now
Office work - few interesting projects occupied me
Laziness - Oh.. never ending

Hmmm.. from where should I begin...

I'll start from the personal things...
My kid... now he's one year old... can walk without being assisted. But somebody has to follow him all the time b'cos he wants to explore everything, everywhere. :-)



I changed my car... Toyota Carina Si MyRoad



A more spacious, comfortable ride than before. But not so good for the pocket...

Thursday, April 19, 2007

Michael Dell uses Ubuntu

Look at Michael Dell's biography here
He uses Ubuntu 7.04 in his home laptop. Must be a beta version since the final version is due this week. (I'm waiting for it to install in my acer notebook)

Wednesday, April 18, 2007

Cricket Humor

I saw the following video sometime back at IESL in the time of our MBA get-together. I found it very hilarious and what a guy Vickram is...

Mihiri has an equally good one here



Tuesday, March 20, 2007

Acer Aspire



My Notebook arrived yesterday. It's Acer Apire 5630 series Core 2 Duo 1.66 GHz (T5500 processor) , 15.4" Wide Screen, 1GB RAM, 160 GB HD, WiFi, 1.3 MP WebCam, 5-in-1 card reader etc. Not that flashy with compared to the notebook I dreamed from Apple (macbook). My poor cash flow prevented me from going for it. This one was $1025 (roughly SLR 115,000) and bought from Amazon. Still couldn't play around with it that much and haven't tested WiFi, LAN and Modem yet. There's a bluetooth button but specs don't say anything about it.

Today I saw the same one with 2GB RAM and nVidia GO 7000 for a lesser price ($999) in amazon. Sigh...

Tuesday, February 27, 2007

Mevinu's pics update


"Am I good for a desktop background?"


"Hey, I can roll now..."


"Hi grand ma, Hi grand pa"

Tech-GSM, two thumbs up...!

I am learning E-commerce as a subject in my MBA and our lecturer most of the times mentions how electronic commerce can be applied in Sri Lankan situation. Here is a good example. I found Tech-GSM web site, a promising company entered into the electronic commerce arena, selling memory related items, and doing it successfully in the local context. They don't have many products listed in their site, most of them are pendrives, SD cards, DIMMS etc. When you want to buy, an E-mail is generated and they'll contact you via your contact details via E-mail or phone. When the order is confirmed, they'll deliver it within Colombo city limits free of charge and you can pay for it at the time of delivery.
I bought a Kingston Data traveler II 2GB pendrive for Rs 3850/- which I found very competitive pricing even when compared with the price given in Amazon.com (only Rs.150 difference). I chose DT II merely because of the data R/W speed which is mentioned as 7 MB/s write and 11 MB/s read. The maximum waiting time to write the entire capacity is less than 5 minutes. (cool...)
To my surprise, they delivered it in the same day I confirmed the order. And the product is Original Kingston which I verified via the Kingston website. Two thumbs up for Tech-GSM guys...

Wednesday, December 27, 2006

SMS Calendar Events

Google Calendar offers free SMS notification service to your mobile phone about the events you save as calendar events. This facility is currently available for Dialog & Celltel connections only. Mmm... neat facility if you have a volatile memory. But there are limitations, only 20 notifications per day and 150 per month.

Wednesday, December 20, 2006

Pics update...



My kid is 3 months old. His name is 'Mevinu Dinsath'. Now he recognizes me and happy whenever I'm around. Most of the days he sees me only in the morning and I think he knows it. So he wakes up early in the morning and he wants me to speak with him. Sometimes I fell sleep while talking to him but he kicks me or shouts loudly to wake me up.
My MBA exam for the 3rd semester is going to start on 30th December and I'm thinking of stay at home for 3-4 days to study. But don't know how long I can do it with the little one.



Mevinu with his mother




with his grandma

Tuesday, October 17, 2006

New Look

I transfered my blog to blogger beta... Mmmm... Looks nice to me...

Life Upgrade!


I rarely post about myself and this is no exception. I became a father on September 18. The little one is a boy and the above picture was taken after 2 hours of birth. (more photos will come soon...)
My friends and colleagues ask how's the life now? My answer is now I feel that I'm living :-) Well, there is no need to mention that I'm busy. Didn't sleep continuously more than two hours since the little one wakes up every two hours. It was very hard during the first two weeks but now I'm used to it. To make the things worse, MBA work load in this semester is like hell. So much of work compared to the previous semester. That's why I couldn't post a single blog during the last three months. I couldn't see any difference in the future also.

Thursday, July 20, 2006

mmmm....

My Office PC is dual boot; having Windows 2003 server and Ubuntu 6.06. I have been in windows for a long time therefore all of my work related files, developments and mail are in windows partitions (ntfs). Ever since I changed to Ubuntu, I was searching ways & means of full access to ntfs partitions. It only gave me read-only access. But today I found this great link on how to get access to ntfs partitions under linux. I immediately implemeted it but due to some reason, it couldn't mount both partitions instead it mounted only one. At least, I have one partition which I have full access.

Well, what more I need? EMail. Yes, I love OutLook. It's a great program. Couldn't believe its from M$. I'm using Thunderbird from mozilla in Linux. The pain is, I cannot use two mail clients in different OSs. Its not only wasting my precious space but also finding a particular mail drives me to nuts. Sometimes I cannot remember which mail is in which mail client. But the beauty of a cross platform mail client like Thunderbird is, it works in both OSs. I found this great article on how to configure Thunderbird to have a single mailbox (profile) no matter in which OS you work. Now I've lost one reason to goto Windows.

Friday, July 14, 2006

wiki

I thought of starting a corporate knowledge base in our company to share views and thoughts of employees mainly on technical topics. I had previous experience of wiki based engines since 'trac' uses a wiki engine to maintain its knowledge base. I googled for wiki engines and came across so many but only two of them impressed me, Twiki & MediaWiki. After installing both, MediaWiki came to the top of the list because of the features it has and the easiness to install. Now it is up and running successfuly. Later I came to konow that wikipedia, the best knowledge base in the world, is also running using MediaWiki. Cool...

Friday, June 30, 2006

The Move

Now I am on the verge of moving to Ubuntu from Windows. I spend 90% of my time on Ubuntu in my dual boot system. Still I'm testing the OS and so far it has being great. I can do most of the things I did in windows without any problem and sometimes better than in windows. Browse using FireFox, Email via Thunderbird, Chat using Gaim, Documentation using OpenOffice etc. And I managed to get most of the third party software to burn CDs, media players, mp3 players and popular codecs to watch dvds and divx movies. Printing, File sharing, SSH, connecting to Remote Desktops and vmware clients are also possible without any glitch. What I missed was .Net & Delphi. I don't do much development work these days and I keep my windows partition for that type of work.

Two days back, I received Ubuntu & Kubuntu CDs which I ordered from Ubuntu web site. They are shipping 3 types of Ubuntu variants for the lates release 6.06 Dapper Drake.
1. Ubuntu - The normal distribution wiht Gnome desktop
2. Kubuntu - Ubuntu with KDE (K-Desktop Environment)
3. Edubuntu - Ubuntu for the entire Family - This has lot of educational programmes for kids.

(I forgot to order Edubuntu but I managed to download it from the site.)

P.S.
I downloaded Ubuntu from a mirror site even before they officially release it :-) I did a kernel upgrade to suit my PIV Hyper Threading PC. Now it recognises two CPUs. Actually there aren't two CPUs but Hyper Threading simulates two CPUs. I installed a customised version of Firefox called SwiftFox which is optimised for PIVs. It loads and runs faster than the normal FireFox.

Thursday, June 22, 2006

Camera Mouse...!

Yeah.. no kidding... there is a camera inside the optical mouse. This is not a very comprehensive one. It is just a CMOS sensor (CMOS sensors are actually being used in inexpensive(?) cameras) which sends images to digital signal processor (DSP) for analysis. This DSP then analyses the image and identifies the patterns in the image to compare it with previous images. Based on the change in patterns, the DSP determines how far the mouse has moved and sends the corresponding coordinates to the computer. Pretty cool huh...

Monday, May 29, 2006

UPDATE!!!!

I'm back after about more than three months! My studies kept me away from most of my enthusiastic activities including blogging. (but I always managed to read other's blogs) I post this, not because it is over, still I'm in the middle of it, to tell you that I'm still alive :-)

Apart from my studies (its a two year MBA), following things kept me busy all the time. I'll post separate entries for each one when I take my mind out of the busy schedule.

1. We were asked to statndardise our software development process introducing version controlling, process tracking, project management, code tesing etc. We thought of trying open source products rather than pumping money on commecial products. I saw CVS has been used by many people to keep the different versions of codes in a repositary. When I was meddling with it, I found a better one called subversion (SVN). I tested it in the windows environment but the results were poor. Then I turned towards Ubuntu (my personal preference) Linux and it was very successfull. Installing and confuguring (i'll post a separate blog entry on this later) svn was really enjoying and it bahave as it is intended to be.

2. Then we wanted to have a project management system and immediately we found that "trac" is a good option. Not only it integrate with svn but also it has other advantages like fully web based, has wiki facility and bug ticket issuing feature. It also get installed without much trouble. (I'll post the steps later)

3. All these (svn and trac) were installed in a temporary machine which was the only one I could find. The specs of the machine are not that appealing, it's a PIII 500MHz, 128MB machine but thanks to Ubuntu, everything went smoothly. All of a sudden we got new PCs, PIV 3GHz with HT, 1GB RAM, 80 GB SATA HD and luckily, I could reserve one PC as a permanent server. We've got one server but got so many requirements. We should have a SQL Server, Apache Tomcat, svn, trac, and many more to come. SQL Server must be running on windows platform and svn & trac must be run on linux. We've got one PC. The only solution I had was to go for PC virtualization. I installed Vmware on top of windows 2003 Server host and installed Ubuntu as a guest. I managed to transfer all the repositories from the previous PC to the new server. (I hope to post a blog entry on this as well). Installation of guest OSs didn't stop there. I installed XP with office 2007 beta, Ubuntu Dapper Drake (ver 6.06) RC. When all these guest OSs are running, the performance degraded a liitle bit but thanks to Hyper Threading, processor managed to keep it in acceptable level.

Friday, February 10, 2006

Father & Son

I copied the following conversation from a blog which I used to read. The person who writes the blog has a six year old son living with his ex-wife. He sees his son once per week. This time, they met in a restaurant;


"Are you eating healthy today, dad?"

"Yeah."

"Do you like eating healthy?"

"Not really. I like hot dogs most."

"Yeah, and you eat a LOT of them."

"I love taking you to lunch. Someday you'll have a little boy that you can take to lunch too."

"Yep. And if you eat healthy you'll get to meet him."

Friday, January 06, 2006

iPod shuffle


The latest addition to my gadget collection, the iPod shuffle, arrived yesterday. Its a cool device in every aspect; size, design, quality,... everything is perfect. It may hold more than 100 songs I assume (its a 512MB) and the battery may last 12 hours according to the manual. Re-charging is possible only when it is connected to a PC via the USB. It supports a wide variety of music formats including mp3, aac, wav etc. Sound quality is good but lacking Bass Power. Its really light weight, not even an ounce. I am braining these days to find a method to connect it to my car audio.

Wednesday, December 21, 2005

Microsoft using FireFox Icon!

Microsoft is planning to use the FireFox RSS icon in IE7 and OutLook 12.

What is great about this news is that Microsoft actually asked the community in the first place, and then worked with the Firefox team to make it happen.