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

output_high2 & output_low2 is now available

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
z3ngew



Joined: 20 Apr 2013
Posts: 50

View user's profile Send private message

output_high2 & output_low2 is now available
PostPosted: Tue Jun 04, 2013 10:33 am     Reply with quote

Hello everyone,
I have wrote a Generic method that will allow CCS users to output_high or output_low two pins that belong to the same port at the same time, for example; PIN_A0, PINA7 without changing its previous state.

the down side of this method is that, when you are using a device with small RAM memory, you will feel like if you RAM has reached over 50%.
but in large RAM memory devices this like 18F452 or example, this should not be a problem

and also there is a manual control the user must make in case your device doesn't have PORT_X ( X is the name of the port).
the user must know the unsupported port name, and then comment the following line concerned with the same port

Code:
//void OUT_X(int8 weight){output_X(weight);}


and remove the it from the output_port array as follow
Code:
// in case your device support PORT A & B
out output_port[5] = {OUT_A, OUT_B};


I leave you now with the code:
Code:
/*
Author: Ahmed Tarek
EMAIL: z3ngew@gmail.com
Code license: freeware
description: this method can output high or output_low 2 pin belonging at
the same port at the same time without changing the last port state
*/
//Feel free to send question on my email

#byte MCU_PORTE = getenv("SFR:PORTE")
#byte MCU_PORTD = getenv("SFR:PORTD")
#byte MCU_PORTC = getenv("SFR:PORTC")
#byte MCU_PORTB = getenv("SFR:PORTB")
#byte MCU_PORTA = getenv("SFR:PORTA")

typedef void (*out)(int8 weight);
void OUT_A(int8 weight){output_A(weight);}
void OUT_B(int8 weight){output_B(weight);}
void OUT_C(int8 weight){output_C(weight);}
void OUT_D(int8 weight){output_D(weight);}
void OUT_E(int8 weight){output_E(weight);}
out output_port[5] = {OUT_A, OUT_B, OUT_C, OUT_D, OUT_E};
int8 weights[9] = {0, 1, 2, 4, 8, 16, 32, 64, 128};
int8 data[5];

void output_high2(int16 PIN1, int16 PIN2)
{
//note this function is for 8 bits uc only
   int16 val1, val2, initial_pin, order;
   data[0] = MCU_PORTA ; data[1] = MCU_PORTB; data[2] = MCU_PORTC; data[3] = MCU_PORTD; data[4] = MCU_PORTE;
   #IFDEF PIN_A0
   initial_pin = PIN_A0;
   #ENDIF
   #IFNDEF PIN_A0
   initial_pin = PIN_B0 - 8;
   #ENDIF
   order = (PIN2 - initial_pin)/8;
   val1 = (PIN1+1 - initial_pin) - ( 8 * order);
   val2 = (PIN2+1 - initial_pin) - ( 8 * order);
   (*output_port[order])(data[order] + (weights[val1] + weights[val2]));
}

void output_low2(int16 PIN1, int16 PIN2)
{
   int16 val1, val2, initial_pin, order;
   data[0] = MCU_PORTA ; data[1] = MCU_PORTB; data[2] = MCU_PORTC; data[3] = MCU_PORTD; data[4] = MCU_PORTE;
   #IFDEF PIN_A0
   initial_pin = PIN_A0;
   #ENDIF
   #IFNDEF PIN_A0
   initial_pin = PIN_B0 - 8;
   #ENDIF
   order = (PIN2 - initial_pin)/8;
   val1 = (PIN1+1 - initial_pin) - ( 8 * order);
   val2 = (PIN2+1 - initial_pin) - ( 8 * order);
   (*output_port[order])(data[order] - (weights[val1] + weights[val2]));
}


How to use these methods?
Simply copy the source code provided in your source file or a different file but make sure to (# include it) and do not forget to follow the instructions mentioned at the beginning of the thread.

Now you can for example use it like this:
Code:
output_high2(PIN_B2, PINB4);
delay_ms(1000);
output_low2(PIN_B2, PIN_B4);


Please feel free to send feedback replies or emails
Good Luck,
z3ngew
byakuya



Joined: 09 Feb 2015
Posts: 4
Location: Mexico

View user's profile Send private message MSN Messenger

PostPosted: Tue Aug 11, 2015 5:43 pm     Reply with quote

Para mi con esto basta amigo


#INCLUDE <18F4550.h>
#FUSES PLL5, CPUDIV1, USBDIV, HSPLL, NOFCMEN, NOWDT, NOPROTECT, NOIESO, PUT
#FUSES NOBROWNOUT, VREGEN, NOWDT, NOSTVREN, NOLVP, NODEBUG, NOPROTECT, NOCPB
#FUSES NOXINST, NOWRT, NOEBTRB, MCLR, NOLPT1OSC, NOPBADEN, STVREN, NODEBUG
#USE DELAY(CLOCK = 48MHZ)

INT8 COLUMNA[8]={PIN_D0,PIN_D1,PIN_D2,PIN_D3,PIN_D4,PIN_D5,PIN_D6,PIN_D7};


VOID MAIN (VOID)
{
FOR(;;)
{
FOR(INT8 I=0; I<7; I++) {
OUTPUT_HIGH(COLUMNA[I]);
DELAY_MS(500);
OUTPUT_LOW(COLUMNA[I]);
DELAY_MS(500);
}
}
}
_________________
Cuando venga la inspiracion que me encuentre trabajando
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library 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