ARM Learning Note II LED lighting program

Source: Internet
Author: User

The first step, first talk about the single-chip microcomputer LED lit:Single chip microcomputer can operate single bit: Sbit    led1    =P1    ^2;    Control the light and extinguish by controlling variable led1;
  
 
  1. #include <reg52.h>
  2. sbit led1 = P1 ^ 2;
  3. void delay(unsigned int xx)//延时
  4. {
  5. int i = 0;
  6. while(xx--)
  7. {
  8. for(i = 0; i < 400; i++);
  9. }
  10. }
  11. int main()
  12. {
  13. while(1)
  14. {
  15. led1 = 1//灭
  16. delay(100);
  17. led1 = 0;//亮
  18. delay(100);
  19. }
  20. }
This is a single-chip computer lighting experiment, we will introduce it to ARM:
ARM can not be like single-chip microcomputer to do a single bit operation, it must be whole, but also very simple ...
     there are so many steps:(1) Analysis Circuit (need to operate which lamp, this is what you want to do)
(2) Analysis drive mode (query register working mode: input/output/...) )
(3) control of the corresponding PIN (query which pin and whether the pin is pulled high or low)

No, just on the code .
  
 
  1. #include <S3C2440.h>
  2. #define LED_A_ON(i) GPADAT &= ~(0x1 << i) //A口i灯亮
  3. #define led_b_on ( i Gpbdat &= ~ ( 0x1 << i ) //b port I Light up
  4. #define Led_a_off Span class= "pun" > ( i Gpadat Span class= "pun" >|= ( 0x1 << i ) //a port I Light up
  5. #define LED_B_OFF(i) GPBDAT |= (0x1 << i) //B口i灯亮
  6. void LED_INIT(void);//初始化控制灯
  7. void delay(unsigned int xx);//延时
  8. int main()
  9. {
  10. LED_INIT();
  11. while(1)//流水灯实验
  12. {
  13. LED_B_ON(5);
  14.     LED_B_OFF(6);
  15.     LED_A_OFF(25);
  16.     LED_A_OFF(26);
  17.     delay(100);
  18.     LED_B_ON(6);
  19.     LED_B_OFF(5);
  20.     LED_A_OFF(25);
  21.     LED_A_OFF(26);
  22.     delay(100);
  23.     LED_A_ON(25);
  24.     LED_B_OFF(5);
  25.     LED_B_OFF(6);
  26.     LED_A_OFF(26);
  27.     delay(100);
  28.     LED_A_ON(26);
  29.     LED_B_OFF(5);
  30.     LED_B_OFF(6);
  31.     LED_A_OFF(25);
  32.     delay(100);
  33. }
  34. }
  35. void LED_INIT()//初始化控制灯
  36. {
  37. GPBCON &= ~(0x03 << 10);//GPB5清零
  38. GPBCON |= (0x01 << 10); //置1
  39. GPACON &= ~(0x3 << 25);
  40. GPADAT |= (0x3 << 25);
  41. GPBDAT |= (0x3 << 5);
  42. delay(10000);
  43. }
compare yourself, isn't it too difficult?


From for notes (Wiz)

ARM Learning Note II LED lighting program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.