Thursday, January 15, 2009

All LED Blinking Program RA4 not Blinking solution .

Previous Tutorial

If you execute the previous program it will work fine except that RA4 wont blink .A quick search showed me that I need to make some extra register configurations with ADCON1 and COMCON registers .

ADCON1 = 0x06 makes all the pins of PORTA as Digital .
COMCON=0x07 disables the comparators

So the rectified program is below .
void main (){

ADCON1 =0x06 ; // Changes PORTA to digital
CMCON = 0x07 ; // Disable analog comparators
PORTA = 0x00 ;
PORTB = 0X00 ;
PORTC = 0X00 ;
PORTD = 0X00 ;
PORTE = 0X00 ;
TRISA = 0x00 ; // Configure PORTA as output
TRISB = 0X00 ;
TRISC = 0X00 ;
TRISD = 0X00 ;
TRISE = 0X00 ;

while(1){
PORTA = 0XFF ;
PORTB = 0XFF ;
PORTC = 0XFF ;
PORTD = 0XFF ;
PORTE = 0Xff ;
Delay_ms(500) ;
PORTA = 0X00 ;
PORTB = 0X00 ;
PORTC = 0X00 ;
PORTD = 0X00 ;
PORTE = 0X00 ;
Delay_ms(500) ;
}
}
Now all this is rectified .The LED's should blink fine .If you think so you are fooled for the second time .Even this program wont make RA4 blink .You need to pull RA4 high in order to make it blink .I am sure you will run into this problem if you are using PORTA .Hope my post helped you .Please leave your valuable comments if you like my blog and a link back if you find it worthy .

PIC16F877 All Led Blinking Program

Have you ever tried the Hello World of Embedded programming ,well I am talking about the LED Blinking program .Well if you have worked with PIC microcontrollers most probably it must have been your first program . My guess is you must have tried it in any 1 one of the pins .(I am talking all this assuming that you are either using PIC16F877,PIC16F877A or PIC16F874A they are all pretty much the same ) .


Only today when I was testing the PIC16f877/877A/874A Development board that I developed I was stuck up with a peculiar problem .I was trying LED blinking program in all the ports simultaneously .And everything worked fine except for RA4 .The LED connected to it didnt blink .It is the 6th pin and remember it iis an ADC outcast :P .Well being in PORTA where the rest of the pins have a inbuilt ADC this pin doesnt have one so I consider it as so .But it serves as a Vref to the comparator .

I wrote this simple program to make all the led's blink in My dev board .

void main (){
PORTA = 0; // Initialize PORTA
PORTB = 0X00 ;
PORTC = 0X00 ;
PORTD = 0X00 ;
PORTE = 0X00 ;
TRISA = 0x00; // Configure PORTA as output
TRISB = 0X00 ;
TRISC = 0X00 ;
TRISD = 0X00 ;
TRISE = 0X00 ;

while(1){
PORTA = 0XFF ;
PORTB = 0XFF ;
PORTC = 0XFF ;
PORTD = 0XFF ;
PORTE = 0Xff ;
Delay_ms(500) ;
PORTA = 0X00 ;
PORTB = 0X00 ;
PORTC = 0X00 ;
PORTD = 0X00 ;
PORTE = 0X00 ;
Delay_ms(500) ;
}
}

If you think this will work , you are in for a surprise .Check out the next post for the answer .


Wednesday, January 14, 2009

My Transition From C to JAVA

Hello Readers 

When I was in college and underwent a course in OOPS c++ and JAVA ,I wondered why do we need this horrible OOPS when easily solve most of the problems using C . And ofcourse the lecturer who handled OOPS was no good .It made my learning experience worse .

But only after I entered my company and took up the JAVA course I found how easy JAVA is and moreover Eclipse makes programming feel like a cool breeze . The ctrl+space code auto generation feature is awesome which programmers will love .But there are some downsides in JAVA as well .Which I found out after some programming experience .You can't play with the memory in JAVA ie there is no such thing as pointers in JAVA .So when it comes to applications where you have to play with the memory you face a down side .But you have something called as Native Method support in JAVA , where you can write a method implementation in some other programming for a JAVA interface .

So explore JAVA and build applications with ease .

Friday, January 2, 2009

MIT Chrompets Annual Techfest -Asymptote

MIT Chrompet for the first time is conducting a Intercollegeite techfest in a big level .

ASYMPTOTE -- (Jan 9 - 11)

It doesn't contain any robotics event as such .But there are lots of technical and management events .

One of my all time favorite event is the Soap Box Derby Car competition its conducted under the name Drag Race .Where in you have to build a model car without any propulsion system .It has to race down the slope under the influence of gravity and reach the finish line .The one that reaches the finish line fastest is the winner .

I remember my days in the 2 nd year of college when I participated in this event .This is one event where you can get hands on experience in mechanical Engineering .So do participate in it and enjoy building the car .

MikroC Code for reading and writing data into EEPROM

<---Previous Tutorial

Here is an example program showing how to read and write into EEPROM ,This program first writes 0x80 into the address 0x00 and the reads and displays it in portb .

unsigned short data = 0x80,address=0x00;

void main() {
PORTB = 0x00;
TRISB = 0x00;

EEprom_Write(address,data); //writes 0x80 into the location 0x00
Delay_ms(20); //insert 20 ms delay between every read and write cycle
PORTB = Eeprom_Read(address); //reads the data from 0x00 and send it to portb
Delay_ms(500);
}