CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

e3 Board Programming

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rogersw8n



Joined: 15 Apr 2015
Posts: 3

View user's profile Send private message

e3 Board Programming
PostPosted: Wed Apr 15, 2015 7:03 pm     Reply with quote

Hi,

I am new to microprocessor development. I purchased the Embedded C Programming book by Mark Siegesmund which came with an e3 board development kit. I have been able to run through the tutorials without too much issue. However, I would like to turn LED's on and off without using the output_high and output_low built in functions. I have read portions of the datasheet describing PORT, TRIS, and LATCH registers. I have set the appropriate PINS to output I believe with TRISC and set the logical value in the LATCH register but the LED does not change state.

Here is my code:
Code:

#include <e3.h>
#include <ios.h>

#define _test

void main(void){

//set_tris_c(8);

struct {
   int bit0;
   int bit1;
   int bit2;
   int bit3;
   int bit4;
   int bit5;
   int bit6;
   int bit7;
} PORTC;
struct {
   int bit0;
   int bit1;
   int bit2;
   int bit3;
   int bit4;
   int bit5;
   int bit6;
   int bit7;
} LATC;
struct {
   int bit0;
   int bit1;
   int bit2;
   int bit3;
   int bit4;
   int bit5;
   int bit6;
   int bit7;
} TRISC;

TRISC = 0xF94;
LATC = 0xF8B;
PORTC = 0xF82;

TRISC.bit3 = 0;


//PORTC = 31763;
while (1){
LATC.bit3 = 1;
delay_ms(1000);
LATC.bit3 = 0;
delay_ms(1000);

}

I am trying to change the red led which is PIN_C3 and works great when using the built in functions.

Two more notes: when running with the built in functions the #define for PIN_C3 is 37163. I have been unable to find what 31763 references. In the datasheet. The address for the TRISC is F94h. The address for LATC is F8B. When viewing the .lst the assembler code for output_high makes changes to F94.3 and F8B.3 with BCF and BSF so I know I have the addresses correct that I assigned to TRISC and LATC in my code.

Thank you very much for your time.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 15, 2015 7:17 pm     Reply with quote

You need to re-do your structures like this:
Code:

struct {
   int bit0 : 1;
   int bit1 : 1;
   int bit2 : 1;
   int bit3 : 1;
   int bit4 : 1;
   int bit5 : 1;
   int bit6 : 1;
   int bit7 : 1;
} PORTC;

This tells the compiler that each element is only 1 bit. Do the other two
structures the same way.

You need to re-do your register assignments as #byte statements, like this:
Code:
#byte TRISC = 0xF94
#byte LATC = 0xF8B
#byte PORTC = 0xF82

All this stuff should be put above main().


Quote:
I have been unable to find what 31763 references.

Using Windows Calculator, convert it to hex and divide it by 8. Then
you'll see the address. Also take the modulus (supported by Windows
calculator) and you'll see the bit number.
rogersw8n



Joined: 15 Apr 2015
Posts: 3

View user's profile Send private message

PostPosted: Wed Apr 15, 2015 7:35 pm     Reply with quote

Thank you very much. All points were exactly right. I see blinking....

Also, I see that converting 31763 to hex is 7C13. Dividing by 8 gets me the PORTC address of F82. Awesome! Why the divide by 8? Thanks for your patience.

Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 15, 2015 7:41 pm     Reply with quote

Because the bit number is encoded in the bottom 3 bits. That's why I
told you to take the modulus of 8, and you'll see the bit number.
rogersw8n



Joined: 15 Apr 2015
Posts: 3

View user's profile Send private message

PostPosted: Wed Apr 15, 2015 7:46 pm     Reply with quote

Got it. Thanks again!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group