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

map overlay struct to discrete pins

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








map overlay struct to discrete pins
PostPosted: Wed Aug 27, 2008 11:42 am     Reply with quote

Hoping to get some help on mapping an 8 bit struct to individual output pins so that i will only need to write 1 byte to the structure and have it overlayed onto the defined pins.

This seems like an optimal way to set or clear bits without having to do each discretely?

Thanks for the advice.

Here is the code that I am trying to get working, but will not compile.

Version 4.057
mplab 7.5


Code:

//#include "PIC_dem2_Header.h"
#define CLK_OSC 20000000//default 20 mhz crystal onboard
#include <18F4520.h>
#device *=16
#fuses HS //INTRC //HS//INTRC
#fuses NOPROTECT,MCLR,NOBROWNOUT,BORV45,NOWDT,WDT128,NOPUT,NOSTVREN,NODEBUG
#fuses NOLVP,NOWRT,NOCPB,NOWRTB,NOWRTC,NOCPD,NOWRTD,NOEBTR,NOEBTRB
#fuses NOXINST   //extended cpu
#use delay(clock=CLK_OSC)


//main function
main(){

//var defines:
struct {
   boolean b1;
   boolean b2;
   boolean b3;
   boolean b4;
   boolean b5;
   boolean b6;
   boolean b7;
   boolean b8;
}bit_array;

//map struct to output pins
//port b of 18f4520
#bit bit_array.b1 = 0xf81.3;//pin_b3
#bit bit_array.b2 =   0xf81.2;//pin_b2
#bit bit_array.b3 = 0xf81.1;//pin_b1
#bit bit_array.b4 =   0xf81.0;//pin_b0
//port a of 18f4520
#bit bit_array.b5 = 0xf80.4;//pin_a4
#bit bit_array.b6 =   0xf80.5;//pin_a5
//port c of 18f4520
#bit bit_array.b7 = 0xf82.2;//pin_c2
#bit bit_array.b8 =   0xf82.3;//pin_c3


//setup periphs:
setup_oscillator(OSC_20MHZ|OSC_NORMAL);



while(1){

//assign one byte and have it mapped to define output pins
bit_array = 0b01010101;
delay_ms(500);
bit_array = 0b10101010;
delay_ms(500);

}//while
}//main
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 27, 2008 12:19 pm     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=18949&start=6
Guest








PostPosted: Wed Aug 27, 2008 2:21 pm     Reply with quote

Thanks PCM. Your a programming GOD.
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