矿石收音机论坛

 找回密码
 加入会员

QQ登录

只需一步,快速开始

搜索
查看: 2777|回复: 3

STM32F030键盘输入十六进制码编程的程序

[复制链接]
     
发表于 2017-12-9 02:17:33 | 显示全部楼层 |阅读模式
有朋友要51的我不会写,写个CORTEX-M0的。

其实应该可以在M0上编写好程序通过串口烧写到51,但是我不懂协议所以不会写。

这个程序实现键盘输入16进制并且通过数码管显示出来,每输入8个16进制数内存地址加4,支持2K编程空间,编写完同时按8和C写入FLASH,没有松手检测哦,看到数码管灭要赶快松手。写到FLASH后按0和4键进入编写好的程序。

瞎玩哦别拍砖啦

  1.         @ stm32f030f4p6 asm
  2.          .thumb                 
  3.          .syntax unified
  4. .section .data       
  5.                .equ STACKINIT,                 0x20001000

  6.         .equ shumaguanma,        0x20000000
  7.         .equ chengxubiao,        0x20000100
  8.         .equ chengxuzhizhen,        0x200000fc
  9.         .equ jianpanzhizhen,        0x200000f8
  10.         .equ anjianhao,                0x200000f4
  11.         .equ anjiancishu,        0x200000f0
  12.         .equ anjian32weipianyi,        0x200000ec
  13. shumaguanmabiao:       
  14.         .int 0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6,0xee,0x3e,0x9c,0x7a,0x9e,0x8e
  15. shumaguanshuaxinbiao:
  16.         .int 0xfe00,0xfd00,0xfb00,0xf700,0xef00,0xdf00,0xbf00,0x7f00,0
  17. jianpansaomiaoma:
  18.         .int 0x80,0x40,0x20,0x10
  19. anjianma:
  20.         .byte 0x18,0x28,0x48,0x88,0x14,0x24,0x44,0x84,0x12,0x22,0x42,0x82,0x11,0x21,0x41,0x81,0x13
  21. .section .text
  22. vectors:        
  23.         .word STACKINIT         
  24.         .word _start + 1        
  25.         .word _nmi_handler + 1  
  26.         .word _hard_fault  + 1  
  27.         .word 0
  28.         .word 0   
  29.         .word 0
  30.         .word 0
  31.         .word 0
  32.         .word 0
  33.         .word 0
  34.         .word _svc_handler +1
  35.         .word 0
  36.         .word 0
  37.         .word _pendsv_handler +1
  38.         .word 0 @_systick +1               @ 15   
  39.         .word 0     @ _wwdg +1          @ 0
  40.         .word 0     @_pvd +1            @ 1
  41.         .word 0     @_rtc +1            @ 2
  42.         .word 0     @_flash +1          @ 3
  43.         .word 0     @ _rcc + 1          @ 4
  44.         .word 0      @_exti0_1  +1      @ 5
  45.         .word 0      @ _exti2_3 +1      @ 6
  46.         .word 0       @_exti4_15 +1     @ 7
  47.         .word 0                         @ 8
  48.         .word 0         @_dma1_1  +1    @ 9
  49.         .word 0    @_dma1_2_3 +1        @ 10
  50.         .word 0       @_dma1_4_5 +1     @ 11
  51.         .word 0 @_adc1 +1          @ 12
  52.         .word 0       @_tim1_brk_up +1  @ 13
  53.         .word 0        @ _tim1_cc +1    @ 14
  54.         .word 0         @_tim2 +1       @ 15
  55.         .word 0          @_tim3 +1      @ 16
  56.         .word 0                         @ 17
  57.         .word 0                                @ 18
  58.         .word @_tim14 +1    @ 19
  59.         .word 0                         @ 20
  60.         .word 0         @_tim16 +1      @ 21
  61.         .word 0         @_tim17 +1      @ 22
  62.         .word 0          @_i2c   +1     @ 23
  63.         .word 0                         @ 24
  64.         .word 0           @_spi   +1    @ 25
  65.         .word 0                         @ 26
  66.         .word 0         @_usart1 +1     @ 27
  67.        
  68. _start:
  69. shizhong:
  70.         ldr r0, = 0x40021000 @ rcc
  71.         ldr r2, = 0x40022000   @FLASH访问控制
  72.         movs r1, # 0x32
  73.         str r1, [r2]           @FLASH缓冲 缓冲开启
  74.         ldr r0, = 0x40021000 @ rcc
  75.         ldr r1, = 0x100002
  76.         str r1, [r0, # 0x04]
  77.         ldr r1, = 0x1000001
  78.         str r1, [r0]
  79. dengrc:
  80.         ldr r1, [r0]
  81.         lsls r1, # 30
  82.         bpl dengrc
  83. dengpll:
  84.         ldr r1, [r0]
  85.         lsls r1, # 6
  86.         bpl dengpll
  87.         @0x34时钟控制寄存器 2 (RCC_CR2)
  88.         movs r1, # 0x01
  89.         str r1, [r0, # 0x34]  @ HSI开14M时钟
  90. dengdai14mshizhongwending:
  91.         ldr r1, [r0, # 0x34]
  92.         lsls r1, r1, # 30     @ 左移30位
  93.         bpl dengdai14mshizhongwending  @ 等待14M时钟稳定

  94. neicunqingling:
  95.         ldr r0, = 0x20000000
  96.         movs r1, # 0
  97.         ldr r3, = 0x1000
  98. neicunqinglingxunhuan:
  99.         subs r3, # 4
  100.         str r1, [r0, r3]
  101.         bne neicunqinglingxunhuan

  102. _waisheshizhong:                 @ 外设时钟
  103.         @+0x14=RCC_AHBENR
  104.         @0=DMA @2=SRAM @4=FLITF@6=CRC @17=PA @18=PB @19=PC @20=PD @22=PF
  105.         ldr r0, = 0x40021000
  106.         ldr r1, = 0x460005
  107.         str r1, [r0, # 0x14]

  108.         @+0x18外设时钟使能寄存器 (RCC_APB2ENR)
  109.         @0=SYSCFG @5=USART6EN @9=ADC @11=TIM1 @12=SPI1 @14=USART1 @16=TIM15 @17=TIM16 @18=TIM17 @22=DBGMCU
  110.         ldr r1, = 0xa00
  111.         str r1, [r0, # 0x18]
  112.         @+0X1C=RCC_APB1ENR
  113.         @1=TIM3 @4=TIM6 @5=TIM7 @8=TIM14 @11=WWDG @14=SPI @17=USRT2 @18=USART3 @20=USART5 @21=I2C1 @22=I2C2 @23=USB @28=PWR
  114.                
  115. io_she_zhi:
  116. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  117.         @a(0x48000000)b(0x48000400)c(0x48000800)d(0x48000c00)f(0x48001400)
  118.         @ 输入(00),通用输出(01),复用功能(10),模拟(11)
  119.         @偏移0x4 = 端口输出类型 @ (0 推挽),( 1 开漏)
  120.         @偏移0x8 = 输出速度  00低速, 01中速, 11高速
  121.         @偏移0xC = 上拉下拉 (00无上下拉,  01 上拉, 10下拉)
  122.         @偏移0x10 = 输入数据寄存器
  123.         @偏移0x14 = 输出数据寄存器
  124.         @偏移0x18 = 端口开  0-15置位
  125.         @偏移0x28 = 端口关
  126.         @0X20 = 复用低
  127.         @GPIO口0(0-3位)每个IO口占用4位
  128.         @ AF0 = 0X0000, AF1 = 0X0001, AF2 = 0X0010 AF3 = 0X0011, AF4 = 0X0100
  129.         @ AF5 = 0X0101, AF6 = 0X0111, AF7 = 0X1000
  130.         @0x24 = 复用高
  131.         @GPIO口8 (0-3位)每个IO口占用4位
  132.         @ AF0 = 0X0000, AF1 = 0X0001, AF2 = 0X0010 AF3 = 0X0011, AF4 = 0X0100
  133.         @ AF5 = 0X0101, AF6 = 0X0111, AF7 = 0X1000
  134. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

  135.         ldr r0, = 0x48000000
  136.         ldr r1, = 0x28045500
  137.         str r1, [r0]
  138.         ldr r2, = 0x240000aa
  139.         str r2, [r0, # 0x0c]
  140.        
  141.        
  142.         ldr r0, = 0x48001400
  143.         movs r1, # 0x05
  144.         str r1, [r0]

  145.         ldr r0, = anjian32weipianyi
  146.         movs r1, # 28
  147.         str r1, [r0]
  148.        
  149.        
  150. _shiyan111:
  151.         ldr r0, = 0x48000010
  152.         ldrb r1, [r0]
  153.         cmp r1, # 0x13                        @把编好的程序写到FLASH,空间2K
  154.         beq _xieflash
  155.         ldr r0, = 0x48000010
  156.         ldrb r1, [r0]
  157.         cmp r1, # 0x1c                       
  158.         beq _jiqimachengxu                @跳转到机器码程序
  159.         bl _juzhenjianpan
  160.         ldr r6, = anjiancishu
  161.         ldr r7, [r6]
  162.         cmp r7, # 16
  163.         bls _tiaoguoanjianzizeng
  164.         movs r7, # 0
  165.         str r7, [r6]
  166.         ldr r0, = chengxubiao
  167.         ldr r1, = chengxuzhizhen
  168.         ldr r2, [r1]
  169.         ldr r4, = anjian32weipianyi
  170.         ldr r5, [r4]
  171.         ldr r3, = anjianhao
  172.         ldr r3, [r3]
  173.         ldr r6, [r0, r2]
  174.         lsls r3, r3, r5
  175.         orrs r3, r3, r6
  176.         str r3, [r0, r2]
  177.         subs r5, r5, # 0x04
  178.         bpl _anjianyiwei
  179.         movs r5, # 28
  180.         adds r2, r2, # 0x04
  181.         str r2, [r1]
  182. _anjianyiwei:       
  183.         str r5, [r4]


  184. _tiaoguoanjianzizeng:       
  185.         ldr r3, = chengxubiao
  186.         ldr r2, = chengxuzhizhen
  187.         ldr r2, [r2]
  188.         ldr r0, [r3, r2]
  189.         ldr r2, = shumaguanma
  190.         bl _zhuanshumaguanma
  191.         movs r0, # 8
  192.         lsls r0, r0, # 2
  193.         bl _xieshumaguan
  194.         b _shiyan111

  195. _juzhenjianpan:
  196.         push {r0-r5}
  197.         ldr r0, = jianpansaomiaoma
  198.         ldr r1, = jianpanzhizhen
  199.         ldr r3, = anjianhao
  200.         ldr r4, = 0x48000000
  201.         ldr r2, [r1]
  202.         adds r2, r2, # 4
  203.         cmp r2, # 16
  204.         bne _tiaochuanjiansaomiao
  205.         movs r2, # 0
  206. _tiaochuanjiansaomiao:
  207.         str r2, [r1]
  208.         ldrb r1, [r0, r2]
  209.         strb r1, [r4, # 0x14]

  210.         ldrb r1, [r4, # 0x10]
  211.         lsls r2, r1, # 28
  212.         lsrs r2, r2, # 28
  213.         movs r2, r2
  214.         beq _meianjian
  215.         ldr r0, = anjianma
  216.         movs r6, # 0
  217. _zhaoanjianma:       
  218.         ldrb r2, [r0, r6]
  219.         cmp r1, r2
  220.         beq _youanjian
  221.         adds r6, r6, # 1
  222.         cmp r6, # 16
  223.         beq _meianjian
  224.         b _zhaoanjianma
  225. _youanjian:
  226.         ldr r0, = anjiancishu
  227.         ldr r1, [r0]
  228.         adds r1, r1, # 1
  229.         str r1, [r0]
  230.         str r6, [r3]
  231.        
  232. _meianjian:       
  233.         pop {r0-r5}
  234.         bx lr

  235. _jiqimachengxu:
  236.         ldr r0, = 0x8000800
  237.         mov pc, r0
  238. _xieflash:                        @ flsh解锁
  239.         ldr r0, = 0x40022000
  240.         ldr r1, = 0x45670123
  241.         str r1, [r0, # 0x04]
  242.         ldr r1, = 0xcdef89ab
  243.         str r1, [r0, # 0x04]
  244.                                         @擦除2页
  245.         movs r5, # 2
  246.         ldr r4, = 0x8000800
  247.         movs r7, # 1
  248.         lsls r7, r7, # 10
  249. _flashmang:
  250.         ldr r2, [r0, # 0x0c]
  251.         lsls r2, r2, # 31
  252.         bmi _flashmang
  253.         movs r1, # 2
  254.         str r1, [r0, # 0x10]
  255.         str r4, [r0, # 0x14]
  256.         movs r1, # 0x42
  257.         str r1, [r0, # 0x10]
  258.         add r4, r4, r7
  259.         subs r5, # 1
  260.         bne _flashmang
  261.                                                 @写FLASH
  262.         ldr r7, = 0x8000800
  263.         ldr r4, = 0x20000100
  264.         movs r5, # 0
  265.         movs r6, # 0x01
  266.         lsls r6, r6, # 9
  267. _flashmang1:
  268.         ldr r2, [r0, # 0x0c]
  269.         lsls r2, r2, # 31
  270.         bmi _flashmang1
  271.         movs r1, # 1
  272.         str r1, [r0, # 0x10]
  273.         ldrh r3, [r4, r5]
  274.         strh r3, [r7, r5]
  275.         adds r5, r5, # 2
  276. _flashmang2:
  277.         ldr r2, [r0, # 0x0c]
  278.         lsls r2, r2, # 31
  279.         bmi _flashmang2
  280.         ldrh r3, [r4, r5]
  281.         strh r3, [r7, r5]
  282.         adds r5, r5, # 2
  283.         subs r6, r6, # 1
  284.         bne _flashmang1
  285. _flashmang3:
  286.         ldr r2, [r0, # 0x0c]
  287.         lsls r2, r2, # 31
  288.         bmi _flashmang3
  289.         movs r1, # 2
  290.         str r1, [r0, # 0x10]
  291.         ldr r3, = 0x8009c00           @ 擦去更新的一页
  292.         str r3, [r0, # 0x14]
  293.         movs r1, # 0x42
  294.         str r1, [r0, # 0x10]
  295. _flashmang4:
  296.         ldr r2, [r0, # 0x0c]
  297.         lsls r2, r2, # 31
  298.         bmi _flashmang4
  299.         @movs r1, # 0x80
  300.         @str r1, [r0]                          @flsh上锁
  301.         ldr r0, = 0xe000ed0c
  302.         ldr r1, = 0x05fa0004
  303.         str r1, [r0]                          @复位


  304.        
  305. _zhuanshumaguanma:                        @ 转数码管码
  306.                 @ R0要转的数据,R2结果表首地址
  307.         push {r0-r7,lr}
  308.         ldr r7, = shumaguanmabiao
  309.         movs r1, # 0
  310. _xunhuanqiuma:
  311.         movs r4, # 28
  312.         subs r4, r4,  r1
  313.         mov r5, r0
  314.         lsls r5, r5, r4
  315.         lsrs r5, r5, # 28
  316.         lsls r5, r5, # 2
  317.         ldr r6, [r7, r5]
  318.         str r6, [r2, r1]
  319.         adds r1, r1, # 0x04
  320.         cmp r1, # 32
  321.         bne _xunhuanqiuma
  322.        
  323.        
  324.         pop {r0-r7,pc}

  325.        
  326. _xieshumaguan:                         @ r0=位数 @数码管码
  327.         push {r0-r7,lr}
  328.         movs r7, # 0
  329.         mov r6, r0
  330.         ldr r5, = shumaguanma
  331.         ldr r2, = shumaguanshuaxinbiao
  332. _shumaguanshuaxin:
  333.         ldr r3, [r5, r7]
  334.         ldr r4, [r2, r7]
  335.         orrs r4, r4, r3
  336.         mov r0, r4
  337.         bl _xie595
  338.         adds  r7, r7, # 4
  339.         cmp r7, r6
  340.         bls _shumaguanshuaxin
  341.         pop {r0-r7,pc}

  342. _xie595:         @ R0=要写的数据
  343.         push {r0-r7,lr}
  344.         mov r5, r0
  345.         ldr r0, =  0x200
  346.         movs r6, # 0x02
  347.         movs r7, # 0x01
  348.         movs r3, # 16   @16位
  349.         movs r1, # 0x01
  350. _xunhuan595:
  351.         ldr r2, = 0x48001400
  352.         str r7, [r2, # 0x18]
  353.         bl _yanshi
  354.         tst r5, r1
  355.         bne _xie595_0
  356.         ldr r2, = 0x48000000
  357.         str r0, [r2, # 0x28]
  358.         b _suocun595
  359. _xie595_0:
  360.         ldr r2, = 0x48000000
  361.         str r0, [r2, # 0x18]
  362. _suocun595:
  363.         bl _yanshi
  364.         lsrs r5, # 1
  365.         ldr r2, = 0x48001400
  366.         str r7, [r2, # 0x28]
  367.         bl _yanshi
  368.         subs r3, r3, # 1
  369.         bne _xunhuan595
  370.         ldr r2, = 0x48001400
  371.         str r6, [r2, # 0x18]
  372.         bl _yanshi
  373.         ldr r2, = 0x48001400
  374.         str r6, [r2, # 0x28]
  375.         bl _yanshi
  376.         pop {r0-r7,pc}
  377.        

  378. _yanshi:
  379.         push {r7,lr}
  380.         ldr r7, = 30
  381. _yanshi11:
  382.         subs r7, # 1
  383.         bne _yanshi11
  384.         pop {r7,pc}

  385. _chufa:                        @软件除法
  386.         @ r0 除以 r1 等于 商(r0)余数R1
  387.         push {r1-r4,lr}
  388.         cmp r0, # 0
  389.         beq _chufafanhui
  390.         cmp r1, # 0
  391.         beq _chufafanhui
  392.         mov r2, r0
  393.         movs r3, # 1
  394.         lsls r3, r3, # 31
  395.         movs r0, # 0
  396.         mov r4, r0
  397. _chufaxunhuan:
  398.         lsls r2, r2, # 1
  399.         adcs r4, r4, r4
  400.         cmp r4, r1
  401.         bcc _chufaweishubudao0
  402.         adds r0, r0, r3
  403.         subs r4, r4, r1
  404. _chufaweishubudao0:
  405.         lsrs r3, r3, # 1
  406.         bne _chufaxunhuan
  407. _chufafanhui:
  408.         pop {r1-r4,pc}
  409.        
  410. _nmi_handler:
  411.         bx lr
  412. _hard_fault:
  413.         bx lr
  414. _svc_handler:
  415.         bx lr
  416. _pendsv_handler:
  417.         bx lr

  418.        
复制代码

jiqima.zip (14.98 KB, 下载次数: 50)
     
 楼主| 发表于 2017-12-9 02:41:43 | 显示全部楼层
1.png

图片 001.jpg

图片 002.jpg
回复 支持 反对

使用道具 举报

     
发表于 2017-12-9 09:18:20 | 显示全部楼层
头回见到用汇编写的ARM程序!高手!不过编写好的程序直接给51用,就我知道的来说,应该不行吧……
回复 支持 反对

使用道具 举报

     
发表于 2017-12-9 10:29:04 | 显示全部楼层
51还是c简单吧。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 加入会员

本版积分规则

小黑屋|手机版|矿石收音机 ( 蒙ICP备05000029号-1 )

蒙公网安备 15040402000005号

GMT+8, 2025-4-30 07:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表