Friday, November 12, 2010

CodeVisionAVR's contra-intuitive pin commmand

For Atmel micro controller programming people often use CodeVisionAVR (http://www.hpinfotech.ro/html/cvavr.htm) which is a good IDE for the development. I recently started to use it myself and I end up spending several hour trying to catch a bug in my code that do not exists. The problem was the following:

CodeVision c language libraries offers you the useful command PINx.y command, per example PINC.1 mean pin 1 of IO port C. But one should know that PINx.y command is meant to be used as read or toggle function only.

read function:
int a = PINC.1 //will assigned the logical value of pin 1 on port C to the variable a

toggle function
//assuming pin 1 of port C is low
PINC.1=1; //  toggle to high
PINC.1=1; //  toggle back to low

To actually write to the output the logical value you really want you should use the PORTx.y command:

PORTC.1=1;   //pin 1 of port C is set to 1
PORTC.1=1;  //pin 1 of port C is set to 1
PORTC.1=0;  //pin 1 of port C is set to0

No comments:

Post a Comment