Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem with the lpc2138 model in proteus

Status
Not open for further replies.

kokimisev

Newbie level 1
Joined
Apr 20, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,326
I have connected lpc2138 model in proteus throught UART0 connection with COMPIM component but it doesn't work so it doesn't send any character. it's connected like on the picture, and the code that I use is:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <includes.h>
 
extern void TimeDelayUS(int uSeconds);
 
/*************************************************************************
 * Function Name: UART0_Init
 *************************************************************************/
void UART0_Init( void )
{
  //UART0 Line Control Register (U0LCR)
  U0LCR_bit.WLS = 0x0;
  U0LCR_bit.SBS = 0;
  U0LCR_bit.PE = 0;
  U0LCR_bit.PS = 0x0;
  U0LCR_bit.BC = 0;
  U0LCR_bit.DLAB = 1;   //Enable access to Divisor Latches.
 
  //UART0 Divisor Latch LSB Register (U0DLL)
  U0DLL = 0x12; //9600 baud (for 115200 use 0x0D)
  
  //UART0 Divisor Latch MSB Register (U0DLM)
  U0DLM = 0x00; //9600 baud (for 115200 use 0x00)
 
  //UART0 Line Control Register (U0LCR)
  U0LCR_bit.WLS = 0x3;  //8 bit character length.
  U0LCR_bit.SBS = 0;    //1 stop bit.
  U0LCR_bit.PE = 0;     //Disable parity generation and checking.
  U0LCR_bit.PS = 0x0;   //Odd parity.
  U0LCR_bit.BC = 0;     //Disable break transmission.
  U0LCR_bit.DLAB = 1;   //Disable access to Divisor Latches.
   
  //UART0 FIFO Control Register (U0FCR)
  U0FCR_bit.FCRFE = 1;      //Enable both UART0 RX and TX FIFOs
  U0FCR_bit.RFR = 1;        //Clear the UART0 RX FIFO.
  U0FCR_bit.TFR = 1;        //Clear the UART0 TX FIFO.
  U0FCR_bit.RTLS = 0x0;     //Set RX trigger level to 1 character.
  
  //UART0 Fractional Divider Register (U0FDR)
  U0FDR_bit.MULVAL = 0xC;     //Baudrate generation pre-scaler divisor value.
  U0FDR_bit.DIVADDVAL = 0x1;  //Baudrate pre-scaler multiplier value.
  
  //UART0 Interrupt Enable Register (U0IER)  
  U0IER_bit.RDAIE = 1;        //Enable the Received Data Available interrupt 
  U0IER_bit.THREIE = 0;       //Enable the Transmit Holding Register Empty interrupt 
  U0IER_bit.RXLSIE = 0;       //Enable the Receiver Line Status interrupt 
  U0IER_bit.ABTOINTEN = 0;    //Enable the End of Autobaud interrupt 
  U0IER_bit.ABEOINTEN = 0;    //Enable the Autobaud Timeout interrupt 
  
}
 
/*************************************************************************
 * Function Name: UART0_TransmitString
 *************************************************************************/
void UART0_TransmitString( char *String )
{ int CharPos = 0;    //Character position inside the string.
  while( String[ CharPos ] )
  { U0THR = String[ CharPos ];
    TimeDelayUS(400);
    U0FCR_bit.TFR = 1;
    CharPos++; }
  }
 
/*************************************************************************
 * Function Name: UART0_ISR
 *************************************************************************/
void UART0_ISR( void )
{ if ( U0IIR_bit.IID == 0x2 )
  { 
  }
}
 
/*************************************************************************
 * Function Name: UART1_Init
 *************************************************************************/
void UART1_Init( void )
{
  //UART1 Line Control Register (U1LCR)
  U1LCR_bit.WLS = 0x0;
  U1LCR_bit.SBS = 0;
  U1LCR_bit.PE = 0;
  U1LCR_bit.PS = 0x0;
  U1LCR_bit.BC = 0;
  U1LCR_bit.DLAB = 1;   //Enable access to Divisor Latches.
 
  //UART1 Divisor Latch LSB Register (U1DLL)
  U1DLL = 0x12; //9600 baud (for 115200 use 0x0D)
  
  //UART1 Divisor Latch MSB Register (U1DLM)
  U1DLM = 0x00; //9600 baud (for 115200 use 0x00)
 
  //UART1 Line Control Register (U1LCR)
  U1LCR_bit.WLS = 0x3;  //8 bit character length.
  U1LCR_bit.SBS = 0;    //1 stop bit.
  U1LCR_bit.PE = 0;     //Disable parity generation and checking.
  U1LCR_bit.PS = 0x0;   //Odd parity.
  U1LCR_bit.BC = 0;     //Disable break transmission.
  U1LCR_bit.DLAB = 1;   //Disable access to Divisor Latches.
   
  //UART1 FIFO Control Register (U1FCR)
  U1FCR_bit.FCRFE = 1;      //Enable both UART1 RX and TX FIFOs
  U1FCR_bit.RFR = 1;        //Clear the UART1 RX FIFO.
  U1FCR_bit.TFR = 1;        //Clear the UART1 TX FIFO.
  U1FCR_bit.RTLS = 0x0;     //Set RX trigger level to 1 character.
  
  //UART1 Fractional Divider Register (U1FDR)
  U1FDR_bit.MULVAL = 0xC;     //Baudrate generation pre-scaler divisor value.
  U1FDR_bit.DIVADDVAL = 0x1;  //Baudrate pre-scaler multiplier value.
  
  //UART1 Interrupt Enable Register (U1IER)  
  U1IER_bit.RDAIE = 0;        //Enable the Received Data Available interrupt 
  U1IER_bit.THREIE = 0;       //Enable the Transmit Holding Register Empty interrupt 
  U1IER_bit.RXLSIE = 0;       //Enable the Receiver Line Status interrupt 
  U1IER_bit.ABTOINTEN = 0;    //Enable the End of Autobaud interrupt 
  U1IER_bit.ABEOINTEN = 0;    //Enable the Autobaud Timeout interrupt 
  
}
 
/*************************************************************************
 * Function Name: UART1_TransmitString
 *************************************************************************/
void UART1_TransmitString( char *String )
{ int CharPos = 0;    //Character position inside the string.
  while( String[ CharPos ] )
  { U1THR = String[ CharPos ];
    TimeDelayUS(400);
    U1FCR_bit.TFR = 1;
    CharPos++; }
  }
 
/*************************************************************************
 * Function Name: UART1_ISR
 *************************************************************************/
void UART1_ISR( void )
{ if ( U1IIR_bit.IID == 0x2 )
  { 
  }
}



I use IAR kickstart 5.0 and the code above works.
Can anybody help me? uart.jpg
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top