.: EMICROS :.  Embedded Micro Software
Home CAN232 CANUSB I2C232 I2CUSB CanWiser Learn C
Add your text here
Contact

Email : info@emicros.com

Ordering Information

.: Ordering using our PayPal powered shopping cart (PayPal account not required).

CAN232 : $79
CANUSB : $89
I2C232 : $79

I2CUSB : $89

Click here to View Cart and check out.

 

 

 

 

Since main is the first function executed after startup, we don't expect to receive any data and we don’t expect to return any data. That is why there is a void declaration in the parentheses and the function name main is preceded with the void declaration.

The first statement in main() is the line TRISC = 0b00000100; which configures the data direction register for Port C. So what's this all about you might ask. In order to set a port pin either high or low on the PIC, we need to configure that particular bit as an output. At reset the normal state of an input/output pin is to be an input which means that the data direction register associated with Port C is set to all zero's. A zero means that the port pin is an input and a 1 indicates that it is an output.

The data direction register for Port C is called TRISC and in order to set Port C Pin 2 as an output we set bit 2 to a 1.

Note that the 0b prefix indicates binary notation and allows a particular bit in this 8 bit byte to be set or cleared individually. We could have just as easily set the value to hexidecimal 0x02 (0x prefix indicates hexidecimal notation) or in this case just decimal 2 (TRISC = 2;).

So where did the TRISC come from? This is actually buried deep in the htc.h include file. One of the reasons this file is there is to provide access to the registers contained within the micro we've selected for our project.

 

 

 
 
Copyright 2010 Embedded Micro Software. All rights reserved