주위!!! 8255관련 부분만 살려놓은 것이니 그냥쓰면 에러날 수 있음.
#define HwBaseAddress 0x00200000
#define HwPortA_DATA 0x00000000
#define HwPortB_DATA 0x00000001
#define HwPortD_DATA 0x00000003
#define HwPortA_DIR 0x00000040
#define HwPortB_DIR 0x00000041
#define HwPortD_DIR 0x00000043
//#define HwPortABCD_Dir 0x00000010
#define BYTE unsigned char
#define WORD unsigned int
/* --- B.C.D to binary value conversion ---
---------------------------------------- */
BYTE to_dval(BYTE x)
{ return ( (x>>4)*10 + (x&15) ); }
/* --- binary to B.C.D value conversion ---
---------------------------------------- */
BYTE to_xval(BYTE x)
{ return ( ((x/10)<<4) | (x%10) ); }
BYTE hex_to_asc(BYTE h)
{
if ( h > 0x09 ) { h = h+0x07; } return (h + 0x30);
}
BYTE asc_to_hex(BYTE a)
{
if (a<0x30) a=0x30; else if (a>0x39) a-=0x07; return (a - 0x30);
}
void delay(unsigned long d_val)
{
unsigned long i,j;
for ( i=0; i < d_val; i++ )
{
for ( j=0; j < 500; j++ ) {}
}
}
unsigned char *volatile pucptr_byte = (unsigned char *)HwBaseAddress;
void gpio_a_out(unsigned char data)
{
pucptr_byte[HwPortA_DIR] = 0xff;
pucptr_byte[HwPortA_DIR] = 0xff;
pucptr_byte[HwPortA_DATA] = data;
}
unsigned char gpio_a_in()
{
pucptr_byte[HwPortA_DIR] = 0x00;
pucptr_byte[HwPortA_DIR] = 0x00;
return(pucptr_byte[HwPortA_DATA]);
}
void gpio_b_out(unsigned char data)
{
pucptr_byte[HwPortB_DIR] = 0xff;
pucptr_byte[HwPortB_DIR] = 0xff;
pucptr_byte[HwPortB_DATA] = data;
}
unsigned char gpio_b_in()
{
pucptr_byte[HwPortB_DIR] = 0x00;
pucptr_byte[HwPortB_DIR] = 0x00;
return(pucptr_byte[HwPortB_DATA]);
}
void gpio_d_out(unsigned char data)
{
pucptr_byte[HwPortD_DIR] = 0x00;
pucptr_byte[HwPortD_DIR] = 0x00;
pucptr_byte[HwPortD_DATA] = data;
}
unsigned char gpio_d_in()
{
pucptr_byte[HwPortD_DIR] = 0xff;
pucptr_byte[HwPortD_DIR] = 0xff;
return(pucptr_byte[HwPortD_DATA]);
}
#define _8255_PORTA 0x00
#define _8255_PORTB 0x01
#define _8255_PORTC 0x02
#define _8255_CW 0x03
#define _8255_WR 0x04
#define _8255_RD 0x08
#define _8255_CS1 0x10
#define _8255_CS2 0x20
#define _8255_RESET 0x40
#define _8255_CTR gpio_b_out
#define _8255_DATA_OUT gpio_d_out
#define _8255_DATA_IN gpio_d_in
void _8255_WR_1(unsigned char addr, unsigned char data)
{
_8255_DATA_OUT(data);
_8255_CTR(0x00 | addr & (~_8255_CS1) | _8255_CS2 & (~_8255_WR) | _8255_RD );
_8255_CTR(0x00 | addr & (~_8255_CS1) | _8255_CS2 | _8255_WR | _8255_RD );
_8255_CTR(0x00 | addr | _8255_CS1 | _8255_CS2 | _8255_WR | _8255_RD );
}
int b1;
unsigned char ccc;
void entry(void)
{
unsigned char bbb;
/*GPIO 디렉션 설정*/
// all output
pucptr_byte[HwPortA_DIR] = 0xff;
// pucptr_byte[HwPortB_DIR] = 0xff;
// pucptr_byte[HwPortD_DIR] = 0x00;
// pucptr_byte[HwPortA_DATA] = 0xff;
// pucptr_byte[HwPortB_DATA] = 0xff;
// pucptr_byte[HwPortD_DATA] = 0xff;
delay(100);
_8255_CTR(0xff & (~_8255_CS1) & (~_8255_CS2) | _8255_RESET ); // reset
delay(1000);
_8255_CTR(0xff);
delay(1000);
_8255_WR_1(_8255_CW, 0x80); // all out put
_8255_WR_1(_8255_PORTA, 0x00);
_8255_WR_1(_8255_PORTB, 0x00);
_8255_WR_1(_8255_PORTC, 0x55);
while(1) // main loop
{
gpio_a_out(0x00);
gpio_a_out(0x00);
gpio_a_out(0x00);
gpio_a_out(0x00);
gpio_a_out(0x00);
gpio_a_out(0xff);
gpio_a_out(0xff);
gpio_a_out(0xff);
gpio_a_out(0xff);
gpio_a_out(0xff);
} // while
}
#define HwBaseAddress 0x00200000
#define HwPortA_DATA 0x00000000
#define HwPortB_DATA 0x00000001
#define HwPortD_DATA 0x00000003
#define HwPortA_DIR 0x00000040
#define HwPortB_DIR 0x00000041
#define HwPortD_DIR 0x00000043
//#define HwPortABCD_Dir 0x00000010
#define BYTE unsigned char
#define WORD unsigned int
/* --- B.C.D to binary value conversion ---
---------------------------------------- */
BYTE to_dval(BYTE x)
{ return ( (x>>4)*10 + (x&15) ); }
/* --- binary to B.C.D value conversion ---
---------------------------------------- */
BYTE to_xval(BYTE x)
{ return ( ((x/10)<<4) | (x%10) ); }
BYTE hex_to_asc(BYTE h)
{
if ( h > 0x09 ) { h = h+0x07; } return (h + 0x30);
}
BYTE asc_to_hex(BYTE a)
{
if (a<0x30) a=0x30; else if (a>0x39) a-=0x07; return (a - 0x30);
}
void delay(unsigned long d_val)
{
unsigned long i,j;
for ( i=0; i < d_val; i++ )
{
for ( j=0; j < 500; j++ ) {}
}
}
unsigned char *volatile pucptr_byte = (unsigned char *)HwBaseAddress;
void gpio_a_out(unsigned char data)
{
pucptr_byte[HwPortA_DIR] = 0xff;
pucptr_byte[HwPortA_DIR] = 0xff;
pucptr_byte[HwPortA_DATA] = data;
}
unsigned char gpio_a_in()
{
pucptr_byte[HwPortA_DIR] = 0x00;
pucptr_byte[HwPortA_DIR] = 0x00;
return(pucptr_byte[HwPortA_DATA]);
}
void gpio_b_out(unsigned char data)
{
pucptr_byte[HwPortB_DIR] = 0xff;
pucptr_byte[HwPortB_DIR] = 0xff;
pucptr_byte[HwPortB_DATA] = data;
}
unsigned char gpio_b_in()
{
pucptr_byte[HwPortB_DIR] = 0x00;
pucptr_byte[HwPortB_DIR] = 0x00;
return(pucptr_byte[HwPortB_DATA]);
}
void gpio_d_out(unsigned char data)
{
pucptr_byte[HwPortD_DIR] = 0x00;
pucptr_byte[HwPortD_DIR] = 0x00;
pucptr_byte[HwPortD_DATA] = data;
}
unsigned char gpio_d_in()
{
pucptr_byte[HwPortD_DIR] = 0xff;
pucptr_byte[HwPortD_DIR] = 0xff;
return(pucptr_byte[HwPortD_DATA]);
}
#define _8255_PORTA 0x00
#define _8255_PORTB 0x01
#define _8255_PORTC 0x02
#define _8255_CW 0x03
#define _8255_WR 0x04
#define _8255_RD 0x08
#define _8255_CS1 0x10
#define _8255_CS2 0x20
#define _8255_RESET 0x40
#define _8255_CTR gpio_b_out
#define _8255_DATA_OUT gpio_d_out
#define _8255_DATA_IN gpio_d_in
void _8255_WR_1(unsigned char addr, unsigned char data)
{
_8255_DATA_OUT(data);
_8255_CTR(0x00 | addr & (~_8255_CS1) | _8255_CS2 & (~_8255_WR) | _8255_RD );
_8255_CTR(0x00 | addr & (~_8255_CS1) | _8255_CS2 | _8255_WR | _8255_RD );
_8255_CTR(0x00 | addr | _8255_CS1 | _8255_CS2 | _8255_WR | _8255_RD );
}
int b1;
unsigned char ccc;
void entry(void)
{
unsigned char bbb;
/*GPIO 디렉션 설정*/
// all output
pucptr_byte[HwPortA_DIR] = 0xff;
// pucptr_byte[HwPortB_DIR] = 0xff;
// pucptr_byte[HwPortD_DIR] = 0x00;
// pucptr_byte[HwPortA_DATA] = 0xff;
// pucptr_byte[HwPortB_DATA] = 0xff;
// pucptr_byte[HwPortD_DATA] = 0xff;
delay(100);
_8255_CTR(0xff & (~_8255_CS1) & (~_8255_CS2) | _8255_RESET ); // reset
delay(1000);
_8255_CTR(0xff);
delay(1000);
_8255_WR_1(_8255_CW, 0x80); // all out put
_8255_WR_1(_8255_PORTA, 0x00);
_8255_WR_1(_8255_PORTB, 0x00);
_8255_WR_1(_8255_PORTC, 0x55);
while(1) // main loop
{
gpio_a_out(0x00);
gpio_a_out(0x00);
gpio_a_out(0x00);
gpio_a_out(0x00);
gpio_a_out(0x00);
gpio_a_out(0xff);
gpio_a_out(0xff);
gpio_a_out(0xff);
gpio_a_out(0xff);
gpio_a_out(0xff);
} // while
}