embpic
Advanced Member level 3
- Joined
- May 29, 2013
- Messages
- 742
- Helped
- 80
- Reputation
- 160
- Reaction score
- 77
- Trophy points
- 1,308
- Location
- india
- Activity points
- 5,213
void toggle_P0_LED0(void) {
if(IOPIN0 & 0x01) IOCLR0 = 0x01;
else IOSET0 = 0x01;
}
but i want to use toggle pin as we do in PIC and 8051 programming.
Writing to the IOPIN register stores the value in the port output register, bypassing the
need to use both the IOSET and IOCLR registers to obtain the entire written value. This
feature should be used carefully in an application since it affects the entire port.
8.5.3Writing to IOSET/IOCLR .vs. IOPIN
Write to the IOSET/IOCLR register allows easy change of the port’s selected output pin(s)
to high/low level at a time. Only pin/bit(s) in the IOSET/IOCLR written with 1 will be set to
high/low level, while those written as 0 will remain unaffected. However, by just writing to
either IOSET or IOCLR register it is not possible to instantaneously output arbitrary binary
data containing mixture of 0s and 1s on a GPIO port.
Write to the IOPIN register enables instantaneous output of a desired content on the
parallel GPIO. Binary data written into the IOPIN register will affect all output configured
pins of that parallel port: 0s in the IOPIN will produce low level pin outputs and 1s in IOPIN
will produce high level pin outputs. In order to change output of only a group of port’s pins,
application must logically AND readout from the IOPIN with mask containing 0s in bits
corresponding to pins that will be changed, and 1s for all others. Finally, this result has to
be logically ORred with the desired content and stored back into the IOPIN register.
Example 2 from above illustrates output of 0xA5 on PORT0 pins 15 to 8 while preserving
all other PORT0 output pins as they were before.
IOPIN ^= 0x1; // this will toggle bit 0
IOPIN ^= 0x2; // this will toggle bit 1
IOPIN ^= 0x4; // this will toggle bit 2
.....
int main(void)
{
VPBDIV = 0x00000000;
PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;
PINSEL2 = 0x00000000;
IO1DIR = (1<<19) | (1<<18) | (1<<17) | (1<<16);
IO1CLR = (1<<19);
while(1)
{
IO1PIN ^= (1<<19);
delay(100);
IO1PIN ^= (1<<19);
delay(100);
}
}
void delay(unsigned int del)
{
unsigned int i,j;
for(i=0;i<del;i++)
for(j=0;j<60000;j++);
}
will it work?
actually i can't check right now i am out of station.
thanx.
- - - Updated - - -
in above code i have toggle one LED.
#include<lpc214x.h>
#define LED1_ON() IO1SET=(1<<16)
#define LED2_ON() IO1SET=(1<<17)
#define LED3_ON() IO1SET=(1<<18)
#define LED4_ON() IO1SET=(1<<19)
#define LED1_OFF() IO1CLR=(1<<16)
#define LED2_OFF() IO1CLR=(1<<17)
#define LED3_OFF() IO1CLR=(1<<18)
#define LED4_OFF() IO1CLR=(1<<19)
void timer0(void)__irq;
void init_timer0(void);
void Initialize(void);
int main(void)
{
Initialize();
while(1);
}
void Initialize(void)
{
VPBDIV = 0x00;
IO1DIR = (1<<19) | (1<<18) | (1<<17) | (1<<16); // Set P1.16, P1.17, P1.18, P1.19 as Output
IO1CLR = (1<<19);
init_timer0();
}
void init_timer0(void)
{
T0IR = 0xff;
T0TC = 0x00;
T0PR = 0x00000020;
T0PC = 0x00;
T0MR0 = 0x0000900;
T0MCR = 0x0001;
T0TCR = 0x02;
VICIntEnable = 0x00000010;
VICIntSelect = 0x00000000;
VICVectCntl0 = 0x00000024;
VICVectAddr0 = (unsigned long)timer0;
T0TCR = 0x01;
}
void timer0(void)__irq
{
T0IR = 0xff;
IO1PIN ^=(1<<19);
}
VICVectAddr = 0; /* Acknowledge Interrupt */
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?