搜索
bottom↓
回复: 7

ELUA stm32例子

[复制链接]

出0入0汤圆

发表于 2015-5-7 15:59:11 | 显示全部楼层 |阅读模式

例子一:按键中断
local keypin

keypin = pio.PA_0

i = 0
pio.pin.setdir(pio.OUTPUT,pio.PA_0)
pio.pin.setpull( pio.PULLDOWN,pio.PA_0)

local prev_gpio



-- This is the GPIO interrupt on change (falling edge) interrupt
local function gpio_posedge_handler( resnum )
    local port, pin = pio.decode( resnum )
  print( string.format( "GPIO POSEDGE interrupt on port %d, pin %d", port, pin ) )
  if prev_gpio then prev_gpio( resnum ) end
end


-- Set GPIO interrupt on change (negative edge) interrupt handler
prev_gpio = cpu.set_int_handler( cpu.INT_GPIO_POSEDGE, gpio_posedge_handler )
-- Enable GPIO interrupt on change (negative edge) for pin 0 of port 0
cpu.sei( cpu.INT_GPIO_POSEDGE, pio.PA_0)


while  uart.getchar( 0, 0 ) == ""  do
end

-- Cleanup
-- Disable the GPIO interrupt on change (negative edge) interrupt
cpu.cli( cpu.INT_GPIO_POSEDGE, keypin)
-- Clear the GPIO interrupt handler
cpu.set_int_handler( cpu.INT_GPIO_POSEDGE, nil );



例子二:定时器中断
local vtmrid = tmr.VIRT0
local to = 1500000

local prev_tmr, new_prev_tmr

-- This is the timer interrupt handler
local function tmr_handler( resnum )
  print( string.format( "Timer interrupt for id %d", resnum ) )
  if prev_tmr then prev_tmr( resnum ) end
end

-- This is the timer interrupt handler that gets set after tmr_handler
local function new_tmr_handler( resnum )
  print( string.format( "NEW HANDLER: timer interrupt for id %d", resnum ) )
  -- This will chain to the previous interrupt handler (tmr_handler above)
  if new_prev_tmr then new_prev_tmr( resnum ) end
end


-- Set timer interrupt handler
prev_tmr = cpu.set_int_handler( cpu.INT_TMR_MATCH, tmr_handler )
-- Setup periodic timer interrupt for virtual timer 0
tmr.set_match_int( vtmrid, to, tmr.INT_CYCLIC )
-- Enable timer match interrupt on virtual timer 0
cpu.sei( cpu.INT_TMR_MATCH, vtmrid )

local tmrid, count = 0, 0
while uart.getchar( 0, 0 ) == "" do
  print "Outside interrupt"
  for i = 1, 1000 do tmr.delay( tmrid, 1000 ) end
  count = count + 1
  if count == 5 then
    print "Changing timer interrupt handler"
    new_prev_tmr = cpu.set_int_handler( cpu.INT_TMR_MATCH, new_tmr_handler )
  end
end

-- Cleanup
-- Stop the timer from generating periodic interrupts
tmr.set_match_int( vtmrid, 0, tmr.INT_CYCLIC );
-- Disable the timer interrupt on match interrupt
cpu.cli( cpu.INT_TMR_MATCH, vtmrid )
-- Clear the timer interrupt handler
cpu.set_int_handler( cpu.INT_TMR_MATCH, nil );


例子在开发板上运行正常

阿莫论坛20周年了!感谢大家的支持与爱护!!

月入3000的是反美的。收入3万是亲美的。收入30万是移民美国的。收入300万是取得绿卡后回国,教唆那些3000来反美的!

出0入0汤圆

发表于 2015-5-7 17:30:47 | 显示全部楼层
代码呢,图呢

出0入0汤圆

 楼主| 发表于 2015-5-7 17:59:19 | 显示全部楼层

贴出来的就是代码

出0入0汤圆

 楼主| 发表于 2015-5-7 18:17:59 | 显示全部楼层
代码见附件

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出100入85汤圆

发表于 2015-5-7 22:38:38 | 显示全部楼层
能运行这个的ELUA STM32工程能共享一下吗?

出0入0汤圆

 楼主| 发表于 2015-5-8 08:36:28 | 显示全部楼层
whatcanitbe 发表于 2015-5-7 22:38
能运行这个的ELUA STM32工程能共享一下吗?

http://www.amobbs.com/forum.php? ... 1&highlight=LUA

出0入0汤圆

发表于 2015-5-8 09:18:40 | 显示全部楼层
正在找这方面的资料呢,谢谢。

出0入0汤圆

 楼主| 发表于 2015-5-8 10:16:30 | 显示全部楼层
lizuqing 发表于 2015-5-8 09:18
正在找这方面的资料呢,谢谢。

STM32F103RC可以跑
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-29 00:25

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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