⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p4.c

📁 y uurug bdf lgdfjg dfg df g dt
💻 C
字号:
// Program to convert the analog data into digital data using the ADC section.
// Connect P0.0-0.7 with ADC Control
// Conect P0.8-0.15 with ADC data
// Connect P0.16-0.23 with LCD data
// Control P0.24-P0.31 with LCD control
 
#include <LPC210x.h> 

#define   PLOCK       0x0400
#define   TIME        20000

#define DISP_FUNC 0x38 		 // sets the display to 8-bit, 2 lines, 5x7 chars + cursor-off 
#define DISP_ENTRY 0x06
#define DISP_CNTL 0x0E
#define DISP_ON 0x04
#define DISP_CURSOR 0x02
#define DISP_CLEAR 0x01
#define DISP_HOME 0x02
#define DISP_POS 0x80
#define DISP_BLINK 0x01
#define DISP_SECOND 0xC0
#define OE 0x01		 // sets the display to 8-bit, 2 lines, 5x7 chars + cursor-off 
#define SOC 0x02
#define ALE 0x04
#define EOC 0x00000008
#define SET0 0x10
#define SET1 0x20
#define SET2 0x40
#define CLOCK 0x80


//#define   LED_ON      IOCLR |= 0xFFFFFFFF
//#define   LED_OFF     IOSET |= 0x00000080

unsigned long b,d,e;
unsigned char temp[5];
void Init(void);
void Delay (unsigned long a); 

signed char i;
char string[16]= "  Advance Tech.";
char string1[16]="Digital O/P    ";

//---------------------------------------------------------
// System initializations
//---------------------------------------------------------
void Init() {
    // Init PLL
    PLLCFG=0x23;                 // P=2, M=4, PLLfreq = 235,9296 Mhz, CCLK = 64 Mhz
    PLLFEED=0xAA; PLLFEED=0x55;
    PLLCON=0x1;                 // Enable the PLL
    PLLFEED=0xAA; PLLFEED=0x55;
    while(!(PLLSTAT & PLOCK));  // Wait for PLL to lock
    PLLCON=0x3;                 // Connect PLL as clock source
    PLLFEED=0xAA; PLLFEED=0x55;   
    //Init MAM & Flash memory fetch
    MAMCR=0x2;                  //mam = flash
    MAMTIM=0x4;
    VPBDIV=0x1;                 //pclk = cclk
    //GPIO init
    IODIR=0xFFFF00F7;           //P0.7 is output(LED)
} 

void Delay (unsigned long e)
{
    while (--e!=0);
}

void inswrt(char c)
{
		b  = (c << 16)|(0x02<<24);
		IOSET=b;
		IOCLR	=	0x02000000;
		IOCLR	=	0xFFFFFFFF;
		Delay(TIME);
}
void datawrt(char c)
{
		b  = (c << 16)|(0x03<<24);
		IOSET=b;
		IOCLR	=	0x03000000;
		IOCLR	=	0xFFFFFFFF;	  
		Delay(TIME);
}

void clock(void)
{
 unsigned int a,b;
 for(b=0;b<=200;b++)
 {
  for(a=0;a<800;a++);
	IOSET=0x00000080;
	for(a=0;a<800;a++);
	IOCLR=0x00000080;
 }
}
//---------------------------------------------------------
// RESET entry
//---------------------------------------------------------


int main()
 {
    Init();                                    
  	IOCLR = 0xFFFFFFFF;
	Delay(TIME);
	inswrt(DISP_FUNC);
	inswrt(DISP_CNTL);
	inswrt(DISP_ENTRY);
	inswrt(DISP_CLEAR);
	for (i=0;i<15;i++)
	datawrt(string[i]);
	inswrt(DISP_SECOND);
	for (i=0;i<15;i++)
	datawrt(string1[i]);
	while(1)
	{
		IOCLR=0xFF00FFFF;
		IOSET=SET0;
		IOSET=SET1;
		IOSET=SET2;
		IOSET=ALE;
		IOSET=SOC;
		clock();
		IOCLR=ALE;
		IOCLR=SOC;
		clock();
		IOPIN = IOPIN & 0x00000000;

		while(IOPIN==0x00000000);
		IOPIN = IOPIN & 0x00000000;
		IOSET=OE;					
		d=IOPIN;
		d=d & 0x0000FF00;
		d=d>>8;
		d=d&0x000000FF;
		inswrt(0xCC);
		for(i=0;i<3;i++)
    	{
	 	temp[i]=d%10;
	 	d=d/10;
    	} 
 		
    	for(i=3;i>=0;i--)
    	{
	 	datawrt(temp[i]+0x30); 	
		}		 
	
	}                                                   
}  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -