Discussion in "ARM Development" started by    arunraj1984    Jun 22, 2011.
Wed Jun 22 2011, 12:37 pm
#1
#include <LPC210X.H>


class uart{

public:

	uart();

	void uart_send_byte(char byte);
	void uart_send_string(const unsigned char *string);
	char uart_receive_byte();
	void uart_receive_string(unsigned char *str,char str_size);
	~uart();
};

uart::uart()    //Initializing uart0 and setting the baud rate 
	{
	PINSEL0 = 0x5;
	U0LCR = 0x83;
	U0DLL = 97;
	U0LCR = 0x03;
	}

	
void uart::uart_send_byte(char byte)
{

U0THR = byte;
while((U0LSR&0x40)==0);
}

char uart::uart_receive_byte()
{
int rec_byte;
while((U0LSR&0x01)==0);
rec_byte = U0RBR;
return(rec_byte);
}

void uart::uart_send_string(const unsigned char *string)
{
while(*string != '\0') 
{
uart_send_byte(*string++);

}
}

void uart::uart_receive_string(unsigned char *str,char str_size)
{


while(str_size != 0)
{
while( (U0LSR&0x01) == 0);
*str = U0RBR; 
str_size--;
str++;
}
		   
}

int main()
{
char data;
unsigned char *data1;
data1 = (unsigned char *)0x40000000;	  
IODIR = 0x10;
uart u1;
while(1)
{
u1.uart_send_string("Press any character\n");
//u1.uart_send_byte(0x0d);
data = u1.uart_receive_byte();
u1.uart_send_byte(data);
//u1.uart_send_byte(0x0d);
u1.uart_send_string("\nTest Passed");
//u1.uart_send_byte(0x0d);
u1.uart_send_string("\nType any string with charecter lenght  ten\n");
//u1.uart_send_byte(0x0d);		 
u1.uart_receive_string(data1,10);

u1.uart_send_string(data1);
//u1.uart_send_byte(0x0d);
u1.uart_send_string("\nTest Passed");

while(1);

}

}



To use it with proteus just uncomment the lines in the main.

IN Proteus i simulated the GPIO, EXTN interrupt and Uart for LPC2106. For me SPI, I2C and CAN does not worked.

IF any one successful in SPI,I2C and CAN Please give examples.

Thankyou

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Kennethbycle
Sun May 12 2024, 03:12 pm
MumerMeags
Sun May 12 2024, 01:47 pm
IsaacZor
Sun May 12 2024, 11:26 am
DavidInomy
Sun May 12 2024, 09:03 am
masagnik1226.ru_gpEn
Sun May 12 2024, 06:50 am
Martinorics
Sun May 12 2024, 02:03 am
Nigarcarm
Sat May 11 2024, 11:22 pm
JefferyBrazy
Sat May 11 2024, 02:33 pm