?? 74hc164_test.c
字號:
;/****************************************Copyright (c)**************************************************
;** 深圳市優(yōu)龍科技有限公司
;**
;** http://www.ucdragon.com
;**
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
#include "..\inc\YL_LPC2103.h"
#include "..\inc\config.h"
U8 const HC164_string[] = "\nPlease enter two numbers(0-f) to turn on the leds\n";//輸入兩個數(shù)字,0到f
/*************************************************************************
* Function Name: UART0_GetChar
* Parameters:
* Return: char
*
* Description: Receive a character from Uart by polling LSR register
*
*************************************************************************/
char UART0_GetChar ( void )
{
U8 Rcv_Data;
while((U0LSR&0x01)==0);
Rcv_Data=U0RBR;
return(Rcv_Data);
}
/*************************************************************************
* Function Name: UART0_PutChar
* Parameters:
* char ch
* Return: void
*
*
* Description: Send character by polling LSR register
*
*************************************************************************/
void UART0_PutChar ( U8 data)
{
U0THR = data; // 發(fā)送數(shù)據(jù)
while( (U0LSR&0x40)==0 ); // 等待數(shù)據(jù)發(fā)送完畢
}
/*************************************************************************
* Function Name: UART0_PutString
* Parameters:
* char *Buf
* Return: int :
*
*
* Description: Send a string by using polling method
*
*************************************************************************/
void UART0_PutString(char *str)
{
while(*str !='\0')
{
UART0_PutChar(*str++);
}
}
/*************************************************************************
* Function Name: UART_Init
* Parameters: Which_Uart DevNum
*
* Return: int
* 0: sucess
* 1: fail
* Description: Initialize Uart, configure baut rate, frame format and FIFO
*
*************************************************************************/
void UART0_Init () //串口0配置
{
U0LCR = 0x83; // DLAB = 1,可設(shè)置波特率
U0DLL = 0x11;
U0DLM = 0x00;
U0LCR = 0x03;
}
/*************************************************************************
* Function Name: main
* Parameters:
*
* Return: void
*
*
* Description:
*
*************************************************************************/
void main( void )
{
U8 no,Display_Bit, Display_Data_Hight, Display_Data_Low; //循環(huán)參數(shù)
PINSEL0 = 0x00000005; // 設(shè)置I/O連接到UART0, P0.4,P0.5,P0.6,P0.7,P0.8為輸出,用來控制LED.
PINSEL1 = 0x00000000;
UART0_Init();
for(;;)
{
UART0_PutString("\nPlease enter two numbers(0-f) to turn on the leds\n");
Display_Data_Hight = UART0_GetChar(); //拿取第一個顯示數(shù)據(jù)
Display_Data_Low = UART0_GetChar(); //拿取第二個顯示數(shù)據(jù)
UART0_PutChar( Display_Data_Hight ); //返回要顯示的數(shù)據(jù)
UART0_PutChar( Display_Data_Low );
if ( Display_Data_Hight == 'a' ) Display_Data_Hight = 0xa;
if ( Display_Data_Hight == 'b' ) Display_Data_Hight = 0xb;
if ( Display_Data_Hight == 'c' ) Display_Data_Hight = 0xc;
if ( Display_Data_Hight == 'd' ) Display_Data_Hight = 0xd;
if ( Display_Data_Hight == 'e' ) Display_Data_Hight = 0xe;
if ( Display_Data_Hight == 'f' ) Display_Data_Hight = 0xf;
if ( Display_Data_Hight == 'A' ) Display_Data_Hight = 0xa;
if ( Display_Data_Hight == 'B' ) Display_Data_Hight = 0xb;
if ( Display_Data_Hight == 'C' ) Display_Data_Hight = 0xc;
if ( Display_Data_Hight == 'D' ) Display_Data_Hight = 0xd;
if ( Display_Data_Hight == 'E' ) Display_Data_Hight = 0xe;
if ( Display_Data_Hight == 'F' ) Display_Data_Hight = 0xf;
else Display_Data_Hight = Display_Data_Hight;
if ( Display_Data_Low == 'a' ) Display_Data_Low = 0xa;
if ( Display_Data_Low == 'b' ) Display_Data_Low = 0xb;
if ( Display_Data_Low == 'c' ) Display_Data_Low = 0xc;
if ( Display_Data_Low == 'd' ) Display_Data_Low = 0xd;
if ( Display_Data_Low == 'e' ) Display_Data_Low = 0xe;
if ( Display_Data_Low == 'f' ) Display_Data_Low = 0xf;
if ( Display_Data_Low == 'A' ) Display_Data_Low = 0xa;
if ( Display_Data_Low == 'B' ) Display_Data_Low = 0xb;
if ( Display_Data_Low == 'C' ) Display_Data_Low = 0xc;
if ( Display_Data_Low == 'D' ) Display_Data_Low = 0xd;
if ( Display_Data_Low == 'E' ) Display_Data_Low = 0xe;
if ( Display_Data_Low == 'F' ) Display_Data_Low = 0xf;
else Display_Data_Low = Display_Data_Low;
IODIR = HC164_Data | HC164_Clk; //設(shè)置移位寄存器的時鐘線和數(shù)據(jù)線為輸出
for ( no = 4; no > 0; no-- )
{
Display_Bit = Display_Data_Hight & ( 0x1 << ( no - 1 ) ); //取最高位,再取第二位,依此類推
if ( Display_Bit == 0 ) IOCLR = HC164_Data; //判斷所取的位是否為0,并發(fā)送該位給74HC164
else IOSET = HC164_Data;
IOSET = HC164_Clk; //拉高時鐘線,上升沿有效
IOCLR = HC164_Clk; //拉底時鐘線,完成一個位的輸入,經(jīng)過8次(參數(shù)no)后完成一個字節(jié)的輸入
}
for ( no = 4; no > 0; no-- )
{
Display_Bit = Display_Data_Low & ( 0x1 << ( no - 1 ) ); //取最高位,再取第二位,依此類推
if ( Display_Bit == 0 ) IOCLR = HC164_Data; //判斷所取的位是否為0,并發(fā)送該位給74HC164
else IOSET = HC164_Data;
IOSET = HC164_Clk; //拉高時鐘線,上升沿有效
IOCLR = HC164_Clk; //拉底時鐘線,完成一個位的輸入,經(jīng)過8次(參數(shù)no)后完成一個字節(jié)的輸入
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -