Sie sind auf Seite 1von 10

ARM7 program

/*********************************************************************
********
*
uarttest.c: main C entry file for Philips LPC214x Family
Microprocessors
*
*
Copyright(C) 2006, Philips Semiconductor
*
All rights reserved.
*
*
History
*
2005.10.01 ver 1.00
Prelimnary version, first Release
*
**********************************************************************
********/
#include "LPC214x.H"
#include "stdio.h"
/* LPC21xx definitions */
#include "type.h"
#include "irq.h"
#include "uart.h"
#include "lcd.h"
#include "target.h"
#include "delay.h"
#include <stdio.h>
#define Relay_1 (1<<24)
#define Relay_2 (1<<25)
#define ir_Sensor (1<<10)
extern DWORD UART0Count;
extern BYTE UART0Buffer[BUFSIZE];
extern DWORD UART1Count;
extern BYTE UART1Buffer[BUFSIZE];
#define UART0_HOST_BAUD 9600
#define UART1_HOST_BAUD 9600
void count();
unsigned char rotatebuf[20],unitbuf[20];
int rotate=0,unit=0;
void intru(void);
/*********************************************************************
********
**
Main Function main()
**********************************************************************
*******/
int main (void)
{
IO1DIR |=Relay_1|Relay_2;
IO0DIR &=~ ir_Sensor;
init_lcd();
lcd_clear();

lcd_putstring(0,"Energy Power");
lcd_putstring(1,"Management");
IO1CLR |=Relay_1;
IO1CLR |=Relay_2;
lcd_clear();
UARTInit(UART1,UART_BAUD(UART1_HOST_BAUD));
setting */
while (1)
{
if((IO0PIN & ir_Sensor)?1:0)
{
rotate=rotate;

/* baud rate

}
else
{
rotate++;
delay(40000);
}
intru();
}
}
void intru(void)
{
sprintf(rotatebuf, "Rotation:-%d",rotate);
lcd_putstring(0,rotatebuf);
sprintf(unitbuf, "UNIT:-%d",unit);
lcd_putstring(1,unitbuf);
if (UART1Count != 0)
{
U1IER = IER_THRE | IER_RLS;
if(UART1Buffer[0] =='C')
{
unit = 15;
IO1SET |=Relay_1;
IO1SET |=Relay_2;
}
else if(UART1Buffer[0] == 'D')
{
unit = 10;
IO1SET |=Relay_1;
IO1CLR |=Relay_2;
}
UARTSend(UART1, UART1Buffer, UART1Count);
UART1Count = 0;
U1IER = IER_THRE | IER_RLS | IER_RBR;
/* Re-enable RBR
*/
}
if(rotate >= 5)
{

rotate=0;
unit--;
if(unit <= 5 && unit>0)
{
IO1SET|=Relay_1;
IO1CLR|=Relay_2;
}
if(unit == 0)
{
IO1CLR|=Relay_1;
IO1CLR|=Relay_2;
}
}
}
#include <LPC21xx.H>
#include "lcd.h"

/* LPC214x definitions */

#define LCD_BACK_LIGHT_TIMEOUT 1000

#define LCD_DATA_DIR
#define LCD_DATA_SET
#define LCD_DATA_CLR

IO0DIR
IO0SET
IO0CLR

#define LCD_CTRL_DIR
#define LCD_CTRL_SET
#define LCD_CTRL_CLR

IO0DIR
IO0SET
IO0CLR

#define LCDRS
#define LCDRW
#define LCDEN
#define
#define
#define
#define

LCD_D4
LCD_D5
LCD_D6
LCD_D7

(1 << 15)
(1 << 16)
(1 << 17)
(1
(1
(1
(1

<<
<<
<<
<<

18)
19)
20)
21)

#define LCD_DATA_MASK
#define LCD_BUSY_FLAG
#define LCD_IO0PIN

(LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7)


LCD_D7
IO0PIN

/**
**********************************************************************
****
****1111

Function Name : delay()


Description :This function suspends the tasks for specified ticks.
Input :

ticks:no of ticks in multiple of 1 usec


task: task to be suspended

Output : void
Note :
**********************************************************************
*********
*/
void delay(int count)
{
int j=0,i=0;
for(j=0;j<count;j++)
{
/* At 60Mhz, the below loop introduces
delay of 10 us */
for(i=0;i<35;i++);
}
}
/**
**********************************************************************
**********************
Function Name :
wait_lcd()
Description

Input

Output

Void

Note
:
**********************************************************************
**********************
*/
void wait_lcd( void )
{
LCD_DATA_DIR &= ~LCD_BUSY_FLAG;
LCD_CTRL_CLR |= LCDRS;
LCD_CTRL_SET |= LCDRW |LCDEN;
while(LCD_IO0PIN & LCD_BUSY_FLAG);
/* wait for busy flag to
become low */
LCD_CTRL_CLR |= LCDEN | LCDRW;
LCD_DATA_DIR |= LCD_DATA_MASK;
delay(100);

}
/**
**********************************************************************
**********************
Function Name :
lcd_command_write()
Description

Input

Output

Void

Note
:
**********************************************************************
**********************
*/
void lcd_command_write( unsigned char command )
{
unsigned char temp=0;
unsigned int temp1=0;
temp=command;
temp=(temp>>4)&0x0F;
temp1=(temp<<18)&LCD_DATA_MASK;
LCD_CTRL_CLR =
LCD_CTRL_SET =
LCD_DATA_CLR =
LCD_DATA_SET =
delay(10000);
LCD_CTRL_CLR =

LCDRS;
LCDEN;
LCD_DATA_MASK;
temp1;
LCDEN;

temp=command;
temp&=0x0F;
temp1=(temp<<18)&LCD_DATA_MASK;
delay(100*2);
LCD_CTRL_CLR |= LCDRS;
LCD_CTRL_SET |= LCDEN;
LCD_DATA_CLR = LCD_DATA_MASK;
LCD_DATA_SET = temp1;
delay(10000);
LCD_CTRL_CLR |= LCDEN;
wait_lcd();
}
/**
**********************************************************************
**********************
Function Name :
set_lcd_port_output()
Description

Input

Output

Void

Note
:
**********************************************************************
**********************
*/
void set_lcd_port_output( void )
{
LCD_CTRL_DIR |= ( LCDEN | LCDRS | LCDRW );
LCD_CTRL_CLR |= ( LCDEN | LCDRS | LCDRW );
LCD_DATA_DIR |= LCD_DATA_MASK;
}
/* *
**********************************************************************
**********************
Function Name :
lcd_clear()
Description

Input

Output

Void

Note
:
**********************************************************************
**********************
*/
void lcd_clear( void)
{
lcd_command_write( 0x01 );
}
/**
**********************************************************************
**********************
Function Name :
lcd_gotoxy()
Description

Input

Output

Void

Note
:
**********************************************************************
**********************
*/
int lcd_gotoxy( unsigned int x, unsigned int y)
{
int retval = 0;

if( (x > 1) && (y > 15) )


{
retval = -1;
} else {
if( x == 0 )
{
lcd_command_write( 0x80
cursor at 0x00 (0x80 + 0x00
} else if( x==1 ){
lcd_command_write( 0xC0
cursor at 0x40 (0x80 + 0x00
}
}
return retval;
}

+ y );
) */

/* command - position

+ y );
) */

/* command - position

/**
**********************************************************************
**********************
Function Name :
lcd_data_write()
Description

Input

Output

Void

Note
:
**********************************************************************
**********************
*/
void lcd_data_write( unsigned char data )
{
unsigned char temp=0;
unsigned int temp1=0;
temp=data;
temp=(temp>>4)&0x0F;
temp1=(temp<<18)&LCD_DATA_MASK;
LCD_CTRL_SET
LCD_DATA_CLR
LCD_DATA_SET
LCD_CTRL_CLR

|= LCDEN|LCDRS;
= LCD_DATA_MASK;
= temp1;
|= LCDEN;

temp=data;
temp&=0x0F;
temp1=(temp<<18)&LCD_DATA_MASK;
LCD_CTRL_SET |= LCDEN|LCDRS;
LCD_DATA_CLR = LCD_DATA_MASK;
LCD_DATA_SET = temp1;

LCD_CTRL_CLR |= LCDEN;
wait_lcd();
}
/**
**********************************************************************
**********************
Function Name :
lcd_putchar()
Description

Input

Output

Void

Note
:
**********************************************************************
**********************
*/
void lcd_putchar( int c )
{
lcd_data_write( c );
}
/**
**********************************************************************
**********************
Function Name :
lcd_putstring()
Description

Input

Output

Void

Note
:
**********************************************************************
**********************
*/
void lcd_putstring( unsigned char line, char *string )
{
unsigned char len = MAX_CHAR_IN_ONE_LINE;
lcd_gotoxy( line, 0 );
while(*string != '\0' && len--)
{
lcd_putchar( *string );
string++;
}
}
/**

**********************************************************************
**********************
Function Name :
lcd_backlight_on()
Description

Input

Output

Void

Note
:
**********************************************************************
**********************
*/
/**
**********************************************************************
**********************
Function Name : turn_off_lcd_back_light()
Description

Input

Output

: Void

Note
:
**********************************************************************
**********************
*/
/**
**********************************************************************
**********************
Function Name :
init_lcd()
Description

Input

Output

Void

Note
:
**********************************************************************
**********************
*/
void init_lcd( void )
{
set_lcd_port_output();
delay(100*2);

lcd_command_write(0x28);
dots.
*/
lcd_command_write(0x02);
*/
lcd_command_write(0x06);
*/
lcd_command_write(0x0F) ;
}

/*

4-bit interface, two line, 5X7

/*

cursor home

/*

Entry mode

/*

display on cursor blinking

*/

/**
**********************************************************************
**********************
Function Name :
test_cmd()
Description

Input

Output

Void

Note
:
**********************************************************************
**********************
*/
void test_cmd(void)
{
//
lcd_command_write(0x38);
// Interface length 8-bit 2 line
lcd_command_write(0x08);
//Display off,cursor off
lcd_command_write(0x0C);
//Display on cursor off
lcd_command_write(0x10);
//Move cursor left by 1 char
lcd_command_write(0x14);
//Move cursor right by 1 char
lcd_command_write(0x01);
//Clear display
}
void delay(int count)
{
int j=0,i=0;
for(j=0;j<count;j++)
{
/* At 60Mhz, the below loop introduces
delay of 10 us */
for(i=0;i<1725;i++);
}
}

Das könnte Ihnen auch gefallen