ucos+ucgui+ Touch screen Control demo__ task

Source: Internet
Author: User

This article is from: http://blog.21ic.com/user1/1425/archives/2008/53102.html

With the Ucos test box, now transplanted Ucos+ucgui, the transplant process can refer to my previous article, I give a project example.
In this project I have set up four tasks:
Task one: Collect analog signals from the outside and save them to the cache, and try to display them on the screen.
Task two: The display of desktop controls and the handling of controls.
Task three: The external resources of the ARM processor, including digital tube, DC motor, AC motor and so on.
Task four: Update the screen, Ucgui recommends using the minimum task level for screen updates.
Task two and task three pass the control information of the touch screen through the mailbox mechanism.

First of all, a simple process of communication between the process can be through the signal volume, mutual exclusion semaphore, mailbox, queue and so on communication mechanisms to communicate with each other, where we use mbox communication, passing a structure pointer.
Just remember the three sentences.
Os_event *conmsg; declaring mailboxes
(1) conmsg = Osmboxcreate (NULL); Create a mailbox
(2) Osmboxpost (conmsg,&conmsg); Send CONMSG message to receive process
(3) Osmboxpend (CONMSG,0,&ERR); Accept mailbox, return message pointer conmsg
*****************************************************************
Here is the main program framework:

/****************************************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//define the stack length for user task 0
#define TASK1STKLENGH 256//define the stack length for user Task 1
#define TASK2STKLENGH 256//define the stack length for user Task 1
#define TASK3STKLENGH 256//define the stack length for user Task 1

OS_STK TASK0STK [Task0stklengh]; To define a stack of user task 0
OS_STK TASK1STK [Task1stklengh]; To define a stack of user task 1
OS_STK TASK2STK [Task2stklengh]; To define a stack of user Task 2
OS_STK TASK3STK [Task3stklengh]; To define a stack of user task 3

void Task0 (void *pdata); Task0 Task 0
void Task1 (void *pdata); Task1 Task 1
void Task2 (void *pdata); Task1 Task 2
void Task3 (void *pdata); Task1 Task 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 transplant experiment example
* * Input: None
* * Output: System return value 0
***********************************************************************/
int main (void)
{
Uint8 err;

Osinit ();
Gui_init ();
INITI2C (); Initializing I2C Registers

Uart_select (0); Select serial Port 0
Uart_init (115200); Initialize serial port 0
Targetinit ();
Eint_init ();

Uart_sendstr ("The System is Start runing!!!!! /n ");
Rgphdat = Rgphdat |           BEEP; BEEP = 1

Touchinit (); Initialize touch screen (ADC)
Irqenable (); Enable IRQ Interrupt (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]; Seconds of the Single-digit
timebuf[3]=duanma[(time%12000)/2000]; Seconds of 10 bits
timebuf[4]=duanma[(time/12000)%10]; Minute digit
timebuf[5]=duanma[(time%720000)/120000]; Minutes 10 bits
timebuf[6]=duanma[(time/720000)%10]; Hour Single-digit
timebuf[7]=duanma[(time%72000000)/7200000]; Hour 10 bits

Suba[0] = 1; 1-bit sub-address
SUBA[1] = 0x10; Child Address
Isendstr (Zlg7290,suba, Timebuf, 8); Show Current Time
Dong[0] = 0x11;
Isendstr (zlg7290,suba,dong,1);

}
/***********************************************************************
* * NAME:IRQ_EINT4
* * DEIONS:EINT4 Interrupt Service program. The output signal of the LED1 control port is reversed.
* * Input: None
* * Output: None
**********************************************************************/
void Irq_eint4 (void)
{
int i;
Uint8 suba[2];

Rgpfcon = Rgpfcon | (0X02<<8); Set back EINT4 interrupt port

Suba[0] = 1; 1-bit sub-address
SUBA[1] = 0x01; Child Address
Ircvstr (zlg7290,suba,sd,3); Read the value of the key

Keynum = sd[0]; Normal key key value
low = keynum%10; Low byte of key value
High = KEYNUM/10; High byte of key value
Timebuf[0] = Duanma[low];
TIMEBUF[1] = Duanma[high];

if (keynum!=0)
{
Runbeep (); Have the normal key to press
Suba[0] = 1; 1-bit sub-address
SUBA[1] = 0x10; Child Address
Isendstr (zlg7290, Suba,timebuf, 8); Low byte output key value
}

Rgpfcon = Rgpfcon |     (0X02<<8); Set back EINT4 interrupt port

Clear Interrupt Flag
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: External interrupt initialization. Set the GPF4 pin for the external interrupt EINT4 function, drop along the triggering mode, and enable interrupts to be allowed.
* * Input: None
* * Output: None
************************************************************************/
void Eint_init (void)
{
Rgpfcon = (Rgpfcon & 0xFFFFFCFF) | (0X02&LT;&LT;8); Set GPF4 pins for external interrupt EINT4 function
rEXTINT0 = (0x2<<16); External interrupt EINT4 set to drop along trigger
VICVECTADDR[4] = (UInt32) irq_eint4; Interrupt Vector Address setting

rpriority = 0x00000000; Use the default fixed priority
Rintmod = 0x00000000; All interrupts are IRQ interrupts
Rintmsk &= ~0x0000010; To cause to EINT4 interruption.
Reintmask &= ~0x0000010;
}
/************************************************************************
* * Name:runbeep
* * Deions: Control buzzer is a sound.
* * 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: Control LED1~LED4 Displays the specified 16 value. LED4 for the highest position,
* * LED1 is the lowest, light indicates that the bit is 1.
* * Input:dat Display value (low 4 digits valid)
* * Output: None
***********************************************************************/
void Led_dispnum (UInt32 dat)
{
dat = dat & 0x0000000f; Parameter filtering
Control LED4, LED3 display (D3, D2 bit)
if (Dat & 0x08) Rgphdat = Rgphdat | (0X01&LT;&LT;6);
else Rgphdat = Rgphdat & (~ (0x01<<6));
if (Dat & 0x04) Rgphdat = Rgphdat | (0X01&LT;&LT;4);
else Rgphdat = Rgphdat & (~ (0x01<<4));
Rgpedat = (Rgpedat & (~ (0x03<<11)) | ((dat&0x03) << 11); Control LED2, LED1 display (D1, D0 bit)
}

/********************************************************************* 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.