Guest
|
map overlay struct to discrete pins |
Posted: Wed Aug 27, 2008 11:42 am |
|
|
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 |
|
|