UCOS + ucgui + touch screen control demo

Source: Internet
Author: User

From: http://blog.21ic.com/user1/1425/archives/2008/53102.html

 

I used Zhou ligong's test box. Now I have transplanted UCOS + ucgui. For the porting process, refer to the previous article. Below I will provide a project example.
In this project, I have created four tasks:
Task 1: Collect analog signals from outside and save them to the cache. Try to display them on the screen.
Task 2: Display and processing of the desktop control.
Task 3: External Resources of arm processors, including digital tubes, DC motors, and AC motors.
Task 4: Update screen. We recommend that you use the lowest task level for screen update in ucgui.
Task 2 and Task 3 pass through the mailbox mechanism to transmit the control information of the touch screen.

First, let's talk about inter-process communication. inter-process communication can communicate with each other through semaphores, mutex semaphores, mailboxes, queues, and other communication mechanisms. Here we use mbox communication, transmits a struct pointer.
Just remember the three statements!
OS _event * conmsg; // declare the email address
(1) conmsg = osmboxcreate (null); // create a mailbox
(2) osmboxpost (conmsg, & conmsg); // send a conmsg email to the receiving process
(3) osmboxpend (conmsg, 0, & ERR); // receives the email address and returns the message pointer conmsg.
**************************************** *************************
The main program framework is as follows:

/*************************************** * Copyright (c) ****************
** File name: Main. c
** Last modified Date: 2006-01-11
** Last version: V1.0
** Deions: Main Function
**************************************** ********************************/
# I nclude "config. H"
# I nclude "string. H"

# Define task0stklengh 512 // defines the stack length of user task 0
# Define task1stklengh 256 // defines the stack length of user Task 1
# Define task2stklengh 256 // defines the stack length of user Task 1
# Define task3stklengh 256 // defines the stack length of user Task 1

OS _stk task0stk [task0stklengh]; // defines the stack of user task 0
OS _stk task1stk [task1stklengh]; // defines the stack of user Task 1
OS _stk task2stk [task2stklengh]; // defines the stack of user Task 2
OS _stk task3stk [task3stklengh]; // defines the stack of user Task 3

Void task0 (void * pdata); // task0 task 0
Void task1 (void * pdata); // Task 1
Void task2 (void * pdata); // Task 1 2
Void task3 (void * pdata); // Task 1 3
Void runbeep (void );
Void led_dispnum (uint32 dat );
Void touchinit (void );
Void irq_adctouch (void );
Void adctouch (void );
Int testtouchdown (void );
Void viewxy (void );
Void Showtime (void );
Void eint_init (void );
Void irq_eint4 (void );
Void keypro (uint8 keynum );
/*************************************** ********************************** Name: main
** Deions: main function, UCOS/II porting experiment example
** Input: None
** Output: The system returns 0.
**************************************** *******************************/
Int main (void)
{
Uint8 err;

Osinit ();
Gui_init ();
Initi2c (); // initialize the I2C register

Uart_select (0); // select serial port 0
Uart_init (115200); // initialize the serial port 0
Targetinit ();
Eint_init ();

Uart_sendstr ("the system is start runing !!!!! /N ");
Rgphdat = rgphdat | beep; // beep = 1

Touchinit (); // initialize the touch screen (ADC)
Irqenable (); // enable IRQ interruption (CPSR)

Ostaskcreate (task0, (void *) 0, & task0stk [task0stklengh-1], 2 );
Ostaskcreate (task1, (void *) 0, & task1stk [task1stklengh-1], 3 );
Ostaskcreate (task2, (void *) 0, & task2stk [task2stklengh-1], 4 );
Ostaskcreate (task3, (void *) 0, & task3stk [task3stklengh-1], 5 );
Keystatus =Osflagcreate(0x00, & ERR );
Conmsg = osmboxcreate (null );

Osstart ();
Return 0;
}

/*************************************** ********************************/
Void Showtime (void)
{
Uint8 err;
Uint8 Suba [2];
Uint8 SD [3];
Uint8 dong [4];
Uint8 symbol = 0;

Time = ostimeget ();
Timebuf [2] = duanma [(Time/200) % 10]; // one-digit second
Timebuf [3] = duanma [(time % 12000)/2000]; // ten seconds
Timebuf [4] = duanma [(Time/12000) % 10]; // minute bit
Timebuf [5] = duanma [(time % 720000)/120000]; // ten minutes
Timebuf [6] = duanma [(Time/720000) % 10]; // hourly
Timebuf [7] = duanma [(time % 72000000)/7200000]; // ten hours

Suba [0] = 1; // 1 seat address
Suba [1] = 0x10; // subaddress
Isendstr (zlg7290, Suba, timebuf, 8); // display the current time
Dong [0] = 0x11;
Isendstr (zlg7290, Suba, Dong, 1 );

}
/*************************************** ********************************
** Name: irq_eint4
** Deions: eint4 interrupts the service program. Return the output signal of the led1 control port.
** Input: None
** Output: None
**************************************** ******************************/
Void irq_eint4 (void)
{
Int I;
Uint8 Suba [2];

Rgpfcon = rgpfcon | (0x02 <8); // set the eint4 Interrupt Port Back.

Suba [0] = 1; // 1 seat address
Suba [1] = 0x01; // subaddress
Ircvstr (zlg7290, Suba, SD, 3); // read key value

Keynum = SD [0]; // normal key value
Low = keynum % 10; // The low byte of the key value
High = keynum/10; // The high byte of the key value
Timebuf [0] = duanma [low];
Timebuf [1] = duanma [High];

If (keynum! = 0)
{
// Runbeep (); // press the normal key
Suba [0] = 1; // 1 seat address
Suba [1] = 0x10; // subaddress
Isendstr (zlg7290, Suba, timebuf, 8); // low-byte output key value
}

Rgpfcon = rgpfcon | (0x02 <8); // set the eint4 Interrupt Port Back.

// Clear the interrupt mark
Reintpend = (1 <4 );
Rsrcpnd = (1 <4 );
Rintpnd = rintpnd;
}

Void keypro (uint8 keynum)
{
Switch (keynum)
{
Case 0: uart_sendbyte (64); break;
Case 1: uart_sendbyte (65); break;
Case 2: uart_sendbyte (66); break;
Case 3: uart_sendbyte (67); break;
Case 4: uart_sendbyte (68); break;

}

}
/*************************************** *********************************
** Name: eint_init
** Deions: Initialize an external interrupt. Set the gpf4 pin to the External Interrupt eint4 function, drop along the trigger mode, and enable the interrupt to be allowed.
** Input: None
** Output: None
**************************************** ********************************/
Void eint_init (void)
{
Rgpfcon = (rgpfcon & 0 xfffffcff) | (0x02 <8); // set the gpf4 pin to enable the eint4 function for external interruptions
Rextint0 = (0x2 <16); // set the External Interrupt eint4 to a descent edge trigger.
Vicvectaddr [4] = (uint32) irq_eint4; // interrupt vector Address Settings

Rpriority = 0x00000000; // use the default fixed priority.
Rintmod = 0x00000000; // all interruptions are IRQ interruptions
Rintmsk & = ~ 0x0000010; // enable eint4 interruption
Reintmask & = ~ 0x0000010;
}
/*************************************** *********************************
** Name: runbeep
** Deions: controls the sound of a buzzer.
** Input: None
** Output: None
**************************************** *******************************/
Void runbeep (void)
{
Rgphdat = rgphdat & beep_mask; // beep = 0
Ostimedly (OS _ticks_per_sec/10 );
Rgphdat = rgphdat | beep; // beep = 1
Ostimedly (OS _ticks_per_sec/10 );
}
/*************************************** *********************************
** Name: led_dispnum
** Deions: Controls led1 ~ Led4 displays the specified hexadecimal value. Led4 is the highest bit,
** When led1 is set to 1, the minimum value is 1.
** Input: The value displayed by DAT (four digits below the value)
** Output: None
**************************************** *******************************/
Void led_dispnum (uint32 dat)
{
Dat = dat & 0x0000000f; // filter parameters
// Control led4 and led3 display (D3 and D2 bits)
If (DAT & 0x08) rgphdat = rgphdat | (0x01 <6 );
Else rgphdat = rgphdat &(~ (0x01 <6 ));
If (DAT & 0x04) rgphdat = rgphdat | (0x01 <4 );
Else rgphdat = rgphdat &(~ (0x01 <4 ));
Rgpedat = (rgpedat &(~ (0x03 <11) | (DAT & 0x03) <11); // control led2 and led1 display (D1 and D0 bits)
}

/*************************************** * ***************************** End of File
**************************************** ************************/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.