NES red and White machine simulator 3rd game handle Test Wuyi STM32

Source: Internet
Author: User

The handle is used CD4021, datasheet said support 3v-15v.

Since the handle is 5V powered, the Gpio 3.3V level is on the 2440 board and the STM32 Gpio is 3.3V (also compatible with 5V) levels.

So first on the STM32 test can be used, on the 2440 Development Board.

It's exactly 8 key values that point to 8 LEDs. Press a key and a light will be lit.

C51:

1#include <reg52.h>2 3Sbit CLK = P2 ^2;4Sbit LATCH = P2 ^1;5Sbit DAT0 = P2 ^0;6 7 voidDELAY10US ()//@11.0592mhz8 {9UnsignedChari;Teni =2; One      while(--i); A } -  -UnsignedCharjoypad () the {     -     inti; -UnsignedCharcmd =0; -LATCH =1; + delay10us (); -LATCH =0; +      for(i=0; i<8; i++) A     {         at delay10us (); -         if(DAT0) -         { -CMD |=1<<i; -         } -CLK =1; in delay10us (); -CLK =0; to     } +LATCH = CLK =0; -     returncmd; the } *  $ intMain ()Panax Notoginseng { -UnsignedCharcmd; theCLK = LATCH = DAT0 =0; + delay10us (); A      while(1) the     { +cmd =joypad (); -         //Lighting $P1 =cmd; $     } -}

STM32: The main part, other parts of the source code, can be found in the STM32 classification.

1#include"stm32f10x.h"2#include"bitband.h"3#include"Delay.h"4 5 voidSysteminit ()6 {7RCC-&GT;CR |= Rcc_cr_hseon;/*External Clock Open*/8      while(! (RCC-&GT;CR & Rcc_cr_hserdy));/*Check the flag position to determine if it is continued*/9     TenRCC-&GT;CFGR = rcc_cfgr_ppre1_2;/*APB1 Low Speed Device 2 -way 72m/2=36m*/ OneRcc->cfgr |= Rcc_cfgr_pllmull9;/*PLL 9 times frequency multiplier*/ ARcc->cfgr |= rcc_cfgr_pllsrc;/*HSE as PLL input*/ -      -FLASH-&GT;ACR |=2;/*2 waiting states of 72M*/ the      -RCC-&GT;CR |= Rcc_cr_pllon;/*Enable PLL*/ -      while(! (RCC-&GT;CR & Rcc_cr_hserdy));/*Check the flag position to determine if it is continued*/ -      +RCC-&GT;CFGR |=RCC_CFGR_SW_PLL;/*Select an external clock as the system clock*/ -      while(2! = ((rcc->cfgr>>2) &3));/*Check the flag position to determine if it is continued*/ + } A  at U8 Joypad () - {     -     inti; -U8 cmd =0; -GPC_BSRR (1) =1; -Delay_us (Ten); inGPC_BRR (1) =1; -      for(i=0; i<8; i++) to     {         +Delay_us (Ten); -         //low-Power indicates that a pressed the         if(0= = GPC_IDR (2)) *         { $CMD |=1<<i;Panax Notoginseng         } -GPC_BSRR (0) =1; theDelay_us (Ten); +GPC_BRR (0) =1; A     } theGPC_BRR (0) =1; +GPC_BRR (1) =1; -     returncmd; $ } $  - intMainvoid) - { the U8 cmd; -     //pin Enable clock IOA IOB IOCWuyiRcc->apb2enr |= Rcc_apb2enr_iopaen | Rcc_apb2enr_iopben |Rcc_apb2enr_iopcen; the      -GPIOC-&GT;CRL =0; Wu      -     //Configuring the LED lamp pin mode PC7 AboutGPIOC-&GT;CRL |= Gpio_crl_mode7;//Mode is set to 11:50m output $GPC_BSRR (7) =1; -      -     //configuration handle CLK pin mode PC0 -GPIOC-&GT;CRL |= gpio_crl_mode0;//Mode is set to 11:50m output A     //Default Low Level +GPC_BRR (0) =1; the      -     //configuration handle latch pin mode PC1 $GPIOC-&GT;CRL |= Gpio_crl_mode1;//Mode is set to 11:50m output the     //Default Low Level theGPC_BRR (1) =1; the      the     //handle DAT0 input pin PC2 -GPIOC-&GT;CRL |= gpio_crl_cnf2_1;//10 Input Mode pull-up/ pull-down in     //Setting the drop-down theGPC_BRR (2) =1; the      About     //Cycle lit the      while(1) the     { thecmd =joypad (); +         //If there is input on the dot led -         if(CMD) the         {BayiGPC_ODR (7) =0; the         } the         Else -         { -GPC_ODR (7) =1;  the         } the          the     } the     return 0; -}

NES red and White machine simulator 3rd game handle Test Wuyi STM32

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.