muratmert4
Usta Üye
Fforumdan bir arkadaşın isteği üzerine minik bir örnek.
C:
sbit LED1 at GPIOD_ODR.B12;
sbit LED2 at GPIOD_ODR.B13;
sbit LED3 at GPIOD_ODR.B14;
sbit LED4 at GPIOD_ODR.B15;
unsigned char rcv = 0;
char *yazi="deneme yazi yazma\n\r";
//void data_received();//iv IVT_INT_USART2 ics ICS_AUTO
void set_up();
void USART2_send(unsigned char value);
void yaz(char *s);
void main()
{
set_up();
yaz(yazi);
Delay_ms(500);
while(1)
{
yaz(yazi); Delay_ms(500);
}
}
//-------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------
void data_received()iv IVT_INT_USART2 ics ICS_AUTO //RX interrupt subroutine
{
if(USART2_SRbits.RXNE == 1) //RX buffer veri geldi
{
rcv = (0xFF & USART2_DR); //gelen datayı okuma registeri
}
USART2_send(rcv); //gelen datayı gönder _******deneme için ******* normal rutinde burada olmaz
}
//-------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------
void USART2_send(unsigned char value)
{
USART2_DR = (value);//& 0xFF); // yollanacak datayıusart2 nin registerinden yolla
while(USART2_SRbits.TXE == 0); //data transmisyonu komple bitene kadar bekle
}
//-------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------
void yaz(char *s)
{
while(*s)
{
USART2_send(*s++); // Send Char_karekter yolla
}
}
//-------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------
void set_up()
{
GPIO_Digital_Output(&GPIOD_BASE, _GPIO_PINMASK_12);
GPIO_Digital_Output(&GPIOD_BASE, _GPIO_PINMASK_13);
GPIO_Digital_Output(&GPIOD_BASE, _GPIO_PINMASK_14);
GPIO_Digital_Output(&GPIOD_BASE, _GPIO_PINMASK_15);
UART2_Init_Advanced(9600, _UART_8_BIT_DATA, _UART_NOPARITY, _UART_ONE_STOPBIT, &_GPIO_MODULE_USART2_PA23); // seri port ayarı
USART2_CR1bits.RXNEIE = 1; // seri port enable RX interrupt biti aktif
NVIC_IntEnable(IVT_INT_USART2); // usart2 kesme aktif
Delay_ms(1000);
LED1=1; Delay_ms(1000);
LED1=0; Delay_ms(1000);
LED2=1; Delay_ms(1000);
LED2=0; Delay_ms(1000);
LED3=1; Delay_ms(1000);
LED3=0; Delay_ms(1000);
LED4=1; Delay_ms(1000);
LED4=0; Delay_ms(1000);
}
//-------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------
}
Son düzenleme: