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

📄 blinky.c

📁 Please read your package and describe it at least 40 bytes. System will automatically delete the di
💻 C
字号:
/******************************************************************************/
/* BLINKY.C: LED Flasher                                                      */
/******************************************************************************/
/* This file is part of the uVision/ARM development tools.                    */
/* Copyright (c) 2005-2006 Keil Software. All rights reserved.                */
/* This software may only be used under the terms of a valid, current,        */
/* end user licence from KEIL for a compatible version of KEIL software       */
/* development tools. Nothing else gives you the right to use this software.  */
/******************************************************************************/
                  
#include <stdio.h>
#include <LPC23xx.H>                    /* LPC23xx definitions                */
#include "LCD.h"                        /* Graphic LCD function prototypes    */


/* Function that initializes LEDs                                             */
void LED_Init(void) {
  PINSEL10 = 0;                         /* Disable ETM interface, enable LEDs */
  FIO2DIR  = 0x000000FF;                /* P2.0..7 defined as Outputs         */
  FIO2MASK = 0x00000000;
}

/* Function that turns on requested LED                                       */
void LED_On (unsigned int num) {
  FIO2SET = (1 << num);
}

/* Function that turns off requested LED                                      */
void LED_Off (unsigned int num) {
  FIO2CLR = (1 << num);
}

/* Function that outputs value to LEDs                                        */
void LED_Out(unsigned int value) {
  FIO2CLR = 0xFF;                       /* Turn off all LEDs                  */
  FIO2SET = (value & 0xFF);             /* Turn on requested LEDs             */
}


/* Function for displaying bargraph on the LCD display                        */
void Disp_Bargraph(int pos_x, int pos_y, int value) {
  int i;

  set_cursor (pos_x, pos_y);
  for (i = 0; i < 16; i++)  {
    if (value > 5)  {
      lcd_putchar (0x05);
      value -= 5;
    }  else  {
      lcd_putchar (value);
      value = 0;
    }
  }
}

/* Import external IRQ handlers from IRQ.c file                               */
extern __irq void T0_IRQHandler  (void);
extern __irq void ADC_IRQHandler (void);

/* Import external functions from Serial.c file                               */
extern       void init_serial    (void);
extern int getkey(void);
extern int sendchar(int ch);
/* Import external variables from IRQ.c file                                  */
extern short AD_last;
extern unsigned char clock_1s;

int atoi(char ch[],int n)
{
 	int i,result=0;
	for (i=0;i<n;i++)
		result=result*10+(ch[i]-48);
	return result;
}

void itoa(int n,char c[20])
{
	int i,j,count=0;
	char ch;
	char c1[20];
	for(i=0;i<20;i++)
	{
		c1[i]=-1;
		c[i]=-1;
	}
 	while (n!=0)
	{
		ch=n%10;
		n=n/10;
		ch+=48;
		c1[count]=ch;
		count++;
	}
	j=0;
	for(i=count-1;i>-1;i--)
	{
		c[i]=c1[j];
		j++;
	}
}

int main (void) {
  int i, m,count,num1,num2;
  int numlist;
  char c[20],c1[20],c2[20];
  
  int ch,delay;
  short AD_old, AD_value, AD_print;

  LED_Init();                           /* LED Initialization                 */
//
//  /* Enable and setup timer interrupt, start timer                            */
//  T0MR0         = 11999;                       /* 1msec = 12000-1 at 12.0 MHz */
//  T0MCR         = 3;                           /* Interrupt and Reset on MR0  */
//  T0TCR         = 1;                           /* Timer0 Enable               */
//  VICVectAddr4  = (unsigned long)T0_IRQHandler;/* Set Interrupt Vector        */
//  VICVectCntl4  = 15;                          /* use it for Timer0 Interrupt */
//  VICIntEnable  = (1  << 4);                   /* Enable Timer0 Interrupt     */
//
//  /* Power enable, Setup pin, enable and setup AD converter interrupt         */
//  PCONP        |= (1 << 12);                   /* Enable power to AD block    */
//  PINSEL1       = 0x4000;                      /* AD0.0 pin function select   */
//  AD0INTEN      = (1 <<  0);                   /* CH0 enable interrupt        */
//  AD0CR         = 0x00200301;                  /* Power up, PCLK/4, sel AD0.0 */
//  VICVectAddr18 = (unsigned long)ADC_IRQHandler;/* Set Interrupt Vector       */
//  VICVectCntl18 = 14;                          /* use it for ADC Interrupt    */
//  VICIntEnable  = (1  << 18);                  /* Enable ADC Interrupt        */

  init_serial();                               /* Init UART                   */

  lcd_init();
  lcd_clear();
  lcd_print ("  MCB2300 DEMO  ");
  set_cursor (0, 1);
  lcd_print ("  www.keil.com  ");
  

 // itoa(123,c);
   
  count =0; 	
  for (i=0;i<20;i++)
  	c[i]=-1;
	numlist=0;
  //for (i = 0; i < 20000000; i++);       /* Wait for initial display           */
  
  
  while (1) {                           /* Loop forever                       */
//    AD_value = AD_last;                 /* Read AD_last value                 */
//    if (AD_value != AD_last)            /* Make sure that AD interrupt did    */
//      AD_value = AD_last;               /* not interfere with value reading   */
//    AD_print  = AD_value;               /* Get unscaled value for printout    */
//    AD_value /= 13;                     /* Scale to AD_Value to 0 - 78        */
//    if (AD_old != AD_value)  {          /* If AD value has changed            */
//      AD_old = AD_value;
//      Disp_Bargraph(0, 1, AD_value);    /* Display bargraph according to AD   */
//    }
//    if (clock_1s) {
//      clock_1s = 0;
//      printf ("AD value = 0x%03x\n\r", AD_print);
//    }


		ch=getkey();
		if (ch>47 && ch <58)
		{
			c[count]=ch;
			count++;
		}
		else
		{
			switch (numlist)
			{
			 	case 0 :num1=atoi(c,count);
						for (i=0;i<20;i++)
  							c[i]=-1;
						printf ("Num1=%i \r\n", num1);
						numlist=1;
						break;
				case 1 :num2=atoi(c,count);
						for (i=0;i<20;i++)
  							c[i]=-1;
						printf ("Num2=%i \r\n", num2);
						numlist=2;
						break;
				case 2 :
						itoa(num1+num2,c1);
						printf("Total = ");
						for (i=0;i<20;i++)
							sendchar(c1[i]);
						numlist=1;
						break;

			}

  			count=0;

		}
		

//		if (ch>47 && ch <56)
//		{
//			LED_Off(m);
//			LED_On(ch-48);
//			m = ch -48;
//		}
//		sendchar(ch);
  }
}

⌨️ 快捷键说明

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