Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. /*
  2. ===============================================================================
  3.  Name        : main.c
  4.  Author      :
  5.  Version     :
  6.  Copyright   : Copyright (C)
  7.  Description : main definition
  8. ===============================================================================
  9. */
  10.  
  11. #ifdef __USE_CMSIS
  12. #include "LPC17xx.h"
  13. #endif
  14.  
  15. char leds[6]={0x04,0x10,0x20,0x40,0x02,0x08};//salidas para el display (e,d,c,a,b,f,g)
  16.  
  17. void espera(void);
  18. void configPuertos(void);
  19. int n=0,i=5,ida=1,vuelta=0;
  20. int main(void) {
  21.    
  22.     configPuertos();
  23.     LPC_GPIO0->FIOCLR|=(1<<0);
  24.     while(1) {
  25.         if (ida){
  26.             LPC_GPIO2->FIOPIN=leds[n];
  27.             espera();
  28.             n++;
  29.         }
  30.         if (vuelta){
  31.             LPC_GPIO2->FIOPIN=leds[i];
  32.             espera();
  33.             i--;
  34.         }
  35.  
  36.         if(n>5){n=0;ida=0;vuelta=1;}
  37.         if(i<0){i=5;ida=1;vuelta=0;}
  38.  
  39.     }
  40.     return 0 ;
  41. }
  42.  
  43. void espera(void)
  44. {
  45.     asm ("ESPERA:   MOV     r0,#0x01000000  ");
  46.     asm ("BUCLE:    SUBS    r0,r0,#1        ");
  47.     asm ("          BNE     BUCLE           ");
  48. }
  49.  
  50. void configPuertos(void)
  51. {
  52.     //*************Configuracion de pines***************************
  53.         LPC_GPIO2->FIODIR0=0xFF;//los 8 bits menos significativos como salida
  54.         LPC_GPIO0->FIODIR0=0x01;//ultimo bit menos significativo como salida
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement