lpc 2104 uart

Başlatan taytis, 20 Mart 2011, 12:34:14

taytis

Arkadaşlar selam ;  aşağıdaki kodu derliyoyorum problem yok fakat proteusta simule ettiğimde virtual terminal'den veri almam lazım fakat boş boudrate ayarlarını filan da yaptım ama nafile bu işi pic'te çok basit yapabiliyordum ,burada gözden kaçırdığım nedir.


/************************************************************/
/* PROJECT NAME: Standard IO                                */
/* Project:      LPC2100 Training course                    */
/* Engineer:     T Martin    tmartin@hitex.co.uk            */
/* Filename:     main.c                                       */
/* Language:     C                                         */
/* Compiler:     Keil ARM   V2.00b                          */
/* Assembler:                                            */
/*                                                          */
/************************************************************/
/* COPYRIGHT: Hitex UK Ltd       2005                  */
/* LICENSE:   THIS VERSION CREATED FOR FREE DISTRIBUTION   */
/************************************************************/
/* Function:                                                */
/*                                                          */
/* Example Standard I/O program for LPC2100                 */
/*                                             */
/* Demonstrates interfacing STDIO library function          */
/* to low level drivers                              */
/*                                             */   
/* Oscillator frequency 12.000 Mhz                     */
/* Target board Keil MCB2100                        */
/************************************************************/

#include <LPC21xx.H>
#include <stdio.h>

void UART0 (void);


int main(void)
{
UART0 ();               //Initilise the UART

while(1)
{
printf("\n\n\nHello World, well its traditional \n"); //Call the prinff function

}

}



void UART0 (void)   
{
PINSEL0 = 0x05;       // Select TxD and RxD on pin connect block
U0LCR = 0x80;         //Enable programming of divisor latches

U0DLL = 0xC2;         //Program the divisor latch for 19200 baud
U0DLM = 0x00;

U0LCR = 0x33;         //Program the line control 8\N\1
U0FCR = 0x4F;         //enable the FIFO's
         
}









// nxp sitesinden aşağıdaki kodu buldum fakat yine çalışmadı proteus 7.7 sp2 proteusta problem olabilirmi ?



#define TX_BUFSIZE 80
static unsigned char txbuf[TX_BUFSIZE];
static unsigned char txptr = 0;
static unsigned char typtr = 0;
void UART1_Init(void)
{
// Fpclk = 12.000.000 MHz
// DLM,DLH = Fpclk / (19200*16) = 39 = 0x27
PINSEL0 |= 0x00050000; // Select UART1 RXD/TXD
U1FCR = 7; // Enable and clear FIFO's
U1LCR = 0x83; // 8N1, enable Divisor latch bit
U1DLL = 0x27; // baud rate fixed to 19200 @ PCLK = 12 Mhz
U1DLM = 0;
U1LCR = 3; // Disable Divisor latch bit
}
static void SendString(char *text)
{
if (txptr == 0) // previous message send ?
{
typtr = 0;
while(*text)
{
txbuf[txptr++] = *text++;
if(txptr >= TX_BUFSIZE)
txptr = 0;
}
}
}
static void UART1_Tx_Int(void) // Called from the main loop
{
char i = 16;
if (U1LCR && 0x20) // transmit FIFO empty ?
{
while (i && txptr)
{
U1THR = txbuf[typtr++];
txptr --;
i --;
}
}
}
int main (void)
{
UART1_Init();
while (1)
{
SendString("Hello magnificent world of the LPC2000\r\n");
UART1_Tx_Int();
}
}