* Blinking LED*/
#include <stdio.h> /* not used */
int main(void);
void delay(void);
#define IOREGS_BASE
#define _IO(offset)
#define PORTB
0x1000
*(unsigned char volatile *)(IOREGS_BASE + offset)
_IO(0x04)
/* i/o port B */
int main(void)
{
*/
}
/* Loop to repeatedly turn the LED ON and then turn the LED OFF
while(1)
{
PORTB |= 0x80;
delay();
PORTB &= 0x7F;
delay();
}
return 0; /* not used */
void delay()
{
unsigned short int i=0;
unsigned short int end=0xffff;
}
for(i=0;i<end;i++); /* do nothing but wasting time */
Volatile Modifier
We add the volatile modifier to a variable that can change value outside the scope of the
function. Usually the value of a global variable changes only as a result of explicit
statements in the C function that is currently executing. This paradigm results when a
single program executes from start to finish, and everything that happens is an explicit
result of actions taken by the program. There are two situations that break this simple
paradigm in which the value of a memory location might change outside the scope of a
particular function currently executing:
1) interrupts and
2) input/output ports.
#define PORTB (* unsigned char volatile *) (0x1004)
© Copyright 2026 Paperzz