Файл: Embedded system development and labs for ARM (R. Muresan, 2005).pdf

ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 13.06.2025

Просмотров: 2352

Скачиваний: 4

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

Embedded Systems Development and Labs; The English Edition

VDD33

U2

R7

U1

R5

GND1

74LS573

20

470E

8-LED

OE

VCC

470E

2

D0

2

D0

Q0

19

R8

3

a

D1

3

D1

Q1

18

4

b

DPY

470E

D2

4

D2

Q2

17

R6

5

c

a

D3

5

D3

Q3

16

7

d

470E

f

b

D4

6

15

R4

dp

g

D4

Q4

8

D5

7

D5

Q5

14

9

e

e

470E

c

D6

8

13

R2

f

D6

Q6

10

d

D7

9

D7

Q7

12

1

g

dp

470E

1GND0

GND

G

11

R3

6

VCC

VCC

R1

470E

470E

U8C

VDD33

6

5

CS6

74HC14

Figure 5-14 8-SEG LED Control Circuit

2. Software Program Design

Write the programs according to the hardware architecture. The program includes: keyboard interrupt routine, key recognition program and key display program. The flow diagram of the program is present bellow:

Interrupt

Start

Routine

Environment

Key Pressed?

Read (Ax is

low)

Initialization

Keyboard

Data

Ax low?

Initialization

Recognition

Read Ax+1

Pressed?

Interrupt

Routine

Display

Key Value

Wait

Exit Interrupt

213


Embedded Systems Development and Labs; The English Edition

Figure 5-15 Flow Diagram

5.2.6 Operation Steps

(1)Prepare the Lab environment. Connect the Embest Emulator to the target board. Connect the target board UART0 to PC serial port with the serial cable provided by the Embest development system.

(2)Run the PC Hyper Terminal (set to 115200 bits per second, 8 data bits, none parity, 1 stop bits, none flow control).

(3)Connect the Embest Emulator to the target board. Open the Keyboard_Test.ews project file found in the Keyboard_Test sub directory of the Examples directory. After compiling and linking, connect to the target board and download the program.

(4)Watch that the hyper terminal output is the following:

Embest 44B0X Evaluation Board (S3CEV40)

Keyboard Test Example

Please press one key on keyboard and look at LED…

(5)User can press keys on the 4 x 4 keyboard. The 8-SEG LED will display the results.

(6)After understanding and mastering the lab, finish the Lab exercises.

5.2.7 Sample Programs

1. Variable Initialization

The external interrupt 1 is used in hardware. The related variables, interrupt controller registers, etc. should be initialized in the program.

volatile UCHAR *keyboard_base = (UCHAR *)0x06000000; #define KEY_VALUE_MASK 0x0f

2. Keyboard Inicialization

/***********************************************************************

* name:

init_keyboard

* func:

init keyboard interrupt

* para:

none

* ret:

none

*modify:

*comment:

**********************************************************************/

void init_keyboard()

{

/* enable interrupt */ rINTMOD = 0x0; rINTCON = 0x1;

/* set EINT1 interrupt handler */

rINTMSK =~(BIT_GLOBAL|BIT_EINT1|BIT_EINT4567);

214

Embedded Systems Development and Labs; The English Edition

pISR_EINT1 = (int)KeyboardInt; pISR_EINT4567 = (int)Eint4567Isr;

/* PORT G */

rPCONG

= 0xffff;

// EINT7~0

rPUPG

= 0x0;

// pull up enable

rEXTINT = rEXTINT|0x20;

// EINT1 falling edge mode

rI_ISPC = BIT_EINT1|BIT_EINT4567;

// clear pending bit

rEXTINTPND = 0xf;

// clear EXTINTPND reg

}

3. Interrupt Routine

/*******************************************************************

* name:

KeyboardInt

* func:

keyboard interrupt handler function

* para:

none

* ret:

none

*modify:

*comment:

*********************************************************************/

void KeyboardInt(void)

{

int value;

rI_ISPC = BIT_EINT1;

// clear pending bit

value = key_read(); if(value > -1)

{

Digit_Led_Symbol(value); Uart_Printf("Key is:%x \r",value);

}

}

8-SEG LED is used in the LAB. For the related programs, please refer to Section 4.6 “8-SEG LED Display Lab”.

int Seg[] = { SEGMENT_A, SEGMENT_B, SEGMENT_C, SEGMENT_D, SEGMENT_E, SEGMENT_F, SEGMENT_G, SEGMENT_P}; /*********************************************************************

* name: Digit_Led_Segment

215


Embedded Systems Development and Labs; The English Edition

* func:

8-segment digit LED's segment display control function

* para:

seg_num -- segment number

* ret:

none

*modify:

*comment:

*********************************************************************/

void Digit_Led_Segment(int seg_num)

{

/* segment control */

if( (seg_num >= 0) && (seg_num < 8) ) LED8ADDR = ~Seg[seg_num];

}

4. Key Detection Program

There are 4 different addresses that are used in the 4 x 4 keyboard detection program. The sample program is as following:

/*********************************************************************

* name:

key_read

* func:

read key value

* para:

none

* ret:

key value, -1 -- error

*modify:

*comment:

*******************************************************************/

inline int key_read()

{

int value; char temp;

/* read line 1 */

temp = *(keyboard_base+0xfd); /* not 0xF mean key down */

if(( temp & KEY_VALUE_MASK) != KEY_VALUE_MASK)

{

if( (temp&0x1) == 0 ) value = 3;

else if( (temp&0x2) == 0 ) value = 2;

else if( (temp&0x4) == 0 ) value = 1;

else if( (temp&0x8) == 0 ) value = 0;

216

Embedded Systems Development and Labs; The English Edition

return value;

}

/* read line 2 */

temp = *(keyboard_base+0xfb); /* not 0xF mean key down */

if(( temp & KEY_VALUE_MASK) != KEY_VALUE_MASK)

{

if( (temp&0x1) == 0 ) value = 7;

else if( (temp&0x2) == 0 ) value = 6;

else if( (temp&0x4) == 0 ) value = 5;

else if( (temp&0x8) == 0 ) value = 4;

return value;

}

/* read line 3 */

temp = *(keyboard_base+0xf7); /* not 0xF mean key down */

if(( temp & KEY_VALUE_MASK) != KEY_VALUE_MASK)

{

if( (temp&0x1) == 0 ) value = 0xb;

else if( (temp&0x2) == 0 ) value = 0xa;

else if( (temp&0x4) == 0 ) value = 9;

else if( (temp&0x8) == 0 ) value = 8;

return value;

}

/* read line 4 */

temp = *(keyboard_base+0xef); /* not 0xF mean key down */

if(( temp & KEY_VALUE_MASK) != KEY_VALUE_MASK)

{

if( (temp&0x1) == 0 )

217


Embedded Systems Development and Labs; The English Edition

value = 0xf;

else if( (temp&0x2) == 0 ) value = 0xe;

else if( (temp&0x4) == 0 ) value = 0xd;

else if( (temp&0x8) == 0 ) value = 0xc;

return value;

}

return -1;

}

5.2.8 Exercises

Write a program that can detect and process two keys pressed at the same time.

5.3 Touch Panel Control Lab

5.3.1 Purpose

Learn the design and the control methods used for the touch panel.

Understand the usage of the S3C44B0X LCD controller.

Understand the A/D convert function of the S3C44B0X processor.

Review the display and control program from the LCD Lab.

Review the serial port communication program design of the S3C44B0X processor.

5.3.2 Lab Equipment

● Hardware: Embest S3CEV40 hardware platform, Embest Standard/Power Emulator, PC. ● Software: Embest IDE 2003, Windows 98/2000/NT/XP operation system.

5.3.3 Content of the Lab

Understand the touch panel circuit control and its design. Write programs to get the coordinate values when the touch panel is pressed. Write programs to output the coordinate values of the touch panel through the serial port. Write programs to display 0-9, A-F on the LCD to show the range of the coordinate.

5.3.4 Principles of the Lab

1. Touch Screen Panel (TSP)

A 4-wire resistive touch panel is used by the Embest S3CEV40 Development system. The resolution of the touch panel is 320 x 240 dots. The touch panel system consists of three parts that are the touch panel, the control circuit and the AD converter circuit.

218

Embedded Systems Development and Labs; The English Edition

Since 44B0X chip did not provide this function, a general I/O port can be used for configuration. The TSP includes two surface resistances, namely, X axial surface resistance and Y axial surface resistance. Therefore TSP has 4 terminals. Its equivalent circuitry when the screen is pressed is shown in Figure 5-19. When the system is in the sleep mode (panel not touched) Q4, Q2 and Q3 are closed and Q1 is opened. When the screen is touched, X axial surface resistance and Y axial surface resistance is opened at the touching point. Since the resistance value is very small (about several hundred ohms) a low level signal is generated at EXINT2, which results into interrupt; MCU causes Q2, Q4 to be opened and Q1, Q3 to be closed by controlling the I/O port. S3C44B0X A/D converter channel AIN1 reads X axis coordinates, then closes Q2, Q4, and causes Q1, Q3 to pass. S3C44B0X A/D converter channel AIN0 reads Y-axis coordinates. When the system reaches the coordinate value, Q4, Q2, Q3 are closed and Q1 is opened. The system returns to original state, waiting for the next touch. TSP occupies 44B0X external interrupt-EXINT2, as well as 4 general I/O ports (PE4 ~ PE7).

VDD

PE5

Q3

VDD

AIN1

PE4

TSPX+

Q4

AIN0

TSPY+

TSPY-

EXINT2

PE7

Q1

R

TSPX-

PE6

Q2

VDD

Figure 5-19 The equivalent circuit when touching the screen.

2. A/D Converter Circuit

The 10-bit CMOS ADC (Analog to Digital Converter) of the S3C44B0X controller consists of an 8-channel analog input multiplexer, auto-zeroing comparator, clock generator, 10 bit successive approximation register (SAR), and an output register. This ADC provides software-selection power-down (sleep) mode. Figure 5-23 shows the functional block diagram of S3C440BX A/D converter.

The ADC conversion features are:

Resolution: 10-bit

Differential Linearity Error: +- 1 LSB

Integral Linearity Error: +- 2 LSB (Max. +- 3 LSB)

219


Embedded Systems Development and Labs; The English Edition

Maximum Conversion Rate: 100 KSPS

Input voltage range: 0-2.5V

Input bandwidth: 0-100 Hz (without S/H (sample & hold) circuit)

Low Power Consumption

Figure 5-16 Functional Block Diagram of S3C440BX A/D Converter

1) Register Group

The integrated ADC has the following three registers: ADC control register (ADCCON), ADC Prescaler Register (ADCPSR) and ADC Data Register (ADCDAT).

(1) ADC control register (ADCCON)

(2) ADC Prescaler Register (ADCPSR)

220