Buzzer driver with LED light drive, key driven

Source: Internet
Author: User

One: Led driver writing

To write LED drivers, the first knowledge of the Development Board structure, the Development Board is divided into the core board and the backplane; the first step in writing a driver is to look at the Development Board, find the position of the LED light on the Development Board and the corresponding name; The first step is to view the core Board circuit diagram, and the backplane circuit diagram; Then write the program:

By looking at the development Board we can know the position of the LED lamp on the core board, on the core board to find the LED circuit diagram, Ctrl+f can be quickly found in the document:

  

We can see from the circuit diagram that oneend of the LED lamp has been connected high, as long as the other end of the low level led will be lit.

Then look at the LED pins on the core board:

As we can see, LED1 corresponds to Gpm4_0

The specific usage of the chip data sheet can then be found:

through the manual we can see:gpm4con output, indicating control, set 0 input, indicating detection, Gpm4dat represents its value and pin voltage state for, the value of a moment for the high level, the value of zero indicates the bottom level , the following code:

1.GlobalMain2 Main:3 mov ip, SP4Sub sp, SP, # A5Stmdb sp!, {FP, IP, LR}6Add FP, SP, #87 8 LDR R3, Gpmcon9LDR R0, =0x1Ten str r0, [R3] One  A LDR R3, Gpmdat -LDR R0, =0x0 - str r0, [R3] the  -Add SP, FP, #4 - Ldmdb sp, {fp, SP, PC} -  + Gpmcon: -. Word0x110002e0 +  A Gpmdat: at. Word0x110002e4

The following C language code is to achieve four LED lights flashing

1 #defineGpm4con (* (unsigned long *) 0X110002E0)//macro definition2 #defineGpm4dat (* (unsigned long *) 0x110002e4)3 4 void(*udelay) (int) =0xc3e25f90;5 intMain ()6 {7Gpm4con &= ~0xFFFF;8Gpm4con |=0x1111;9     Ten      while(1) { OneGpm4dat |=0xf;//led off AUdelay (250000); -Gpm4dat &= ~0xf; -Udelay (250000);//led on the     }     -}

Marquee:

1 #defineGpm4con (* (unsigned long *) 0x110002e0)2 #defineGpm4dat (* (unsigned long *) 0x110002e4)3 4 void(*udelay) (int) =0xc3e25f90;5 6 intMain ()7 {8     9Gpm4con &= ~0xFFFF;TenGpm4con |=0x1111; OneUnsignedLongTMP =0xf; A  -      while(1) { -  the         if(TMP &0xf) ==0) { -TMP =0xf; -         } -  +Gpm4dat = tmp <<1; -TMP =Gpm4dat; +Udelay (250000); A  at     } -  -}

Running lights:

1 #defineGpm4con (* (unsigned long *) 0x110002e0)2 #defineGpm4dat (* (unsigned long *) 0x110002e4)3 4 void(*udelay) (int) =0xc3e25f90;5 6 intMain ()7 {8     9Gpm4con &= ~0xFFFF;TenGpm4con |=0x1111; OneUnsignedLongi =0; A      while(1) { -Gpm4dat =0xf; -Gpm4dat &= ~ (1<< i);//Water theUdelay (500000);//Delay -i++; -         if(i = =4) { -i =0; +         }  -     } +  A}

The above procedure always uses the delay function udelay (), because U-boot as the embedded Linux system boot, does not have the standard C library content. To use a function like printf, the delay function udelay () needs to be provided in U-boot. U-boot function content in the U-boot source file needs to be provided in the u-boot. The contents of the U-boot function are in the System.map file in the U-boot source file. the system.map file is a symbol table used by the kernel. The symbol table is a query table between the symbol names and their memory locations. The symbolic name may be the name of the variable or the function name. System.map is required when you want to query the location of a symbol name or a symbolic name at a specific location. Find the corresponding address of the function, it can be used;

Two: Buzzer driver writing:

With the development Board we can see that the buzzer is located on the backplane:

View circuit diagram:

By looking at the Backplane manual, the buzzer will ring when the XpwmTOUT0 is high, and by XpwmTOUT0 we find its pin on the core board.

Then look at the chip manual:

We can see from the figure that Gpd0con is a control control for 0x1: The Gpd0dat is 1 High: The assembly code is posted below:

1.GlobalMain2 Main:3 mov ip, SP4Sub sp, SP, # A5Stmdb sp!, {FP, IP, LR}6Add FP, SP, #87 8 LDR R3, Gpdcon9LDR R0, =0x1Ten str r0, [R3] One  A LDR R3, Gpmdat -LDR R0, =0x1 - str r0, [R3] the  -Add SP, FP, #4 - Ldmdb sp, {fp, SP, PC} -  + Gpdcon: -. Word0x114000a0 +  A Gpmdat: at. Word0x114000a4

C-Language code:

1 #defineGpd0con (* (volatile unsigned long*) 0x114000a0)2 #defineGpd0dat (* (volatile unsigned long*) 0x114000a4)3 4 void(*udelay) (int) =0xc3e25f90;5 intMainvoid)6 {   7Gpd0con =0x0001;8      while(1){9Gpd0dat =0x1;TenUdelay (250000); OneGpd0dat =0x0; AUdelay (250000);//Delay -     } -      the     return 0; -}

Buzzer driver with LED light drive, key driven

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.