图像模块的操作《实验5--中断的使用》

https://docs.openmv.io/openmvcam/quickref.html#external-interrupts

参考网址。。

1、概念,由于模块是用stm32的,和stm32的中断概念一样。
对应0-15条中断线。
比如PD12,对应的是Line12中断线。
PE13对应的是LINE13中断线;
PE12对应LINE12中断线 。

每个LINE智能对一个IO,比如LINE12只能用PD12,而不能同时用PE12.。

2、
注意callback和EXTINT函数的形参的各种形式。
我们一般用下降沿,所以应该用IRQ_FALLING.
callback是中断服务函数,可以自己定义。
比如自己定义一个函数。callback1,在EXTINT中的callback用callback1代替。
函数名要一致。

一旦发生中断,就触发执行中断服务函数。
在这里插入图片描述
在这里插入图片描述
具体在这里插入代码片

# WeAct Studio
# 微行工作室
# TFT ST7735 Test

import sensor, image, time
from ST7735 import TFT,TFTColor
from sysfont import sysfont
from machine import Pin, SPI
import pyb,time
import lcd
from pyb import Pin, ExtInt

pos1=100
pos2=100
#callback_intPD12= lambda e: print("******************intr Int0 is press *****************")
#callback_intPD13= lambda e: print("******************intr IntP8,PD13 is press *****************")
def callbackPD12():
    global pos1
    pos1=1
def callbackPD13():
    global pos1
     pos2=1
        

#extint = pyb.ExtInt(pin, pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, callback)
ext0 = ExtInt(Pin('P7'), ExtInt.IRQ_FALLING, Pin.PULL_UP, callbackPD12)
ext1 = ExtInt(Pin('P8'), ExtInt.IRQ_FALLING, Pin.PULL_UP, callbackPD13)





spi = SPI(-1, baudrate=20000000, polarity=0, phase=0, sck=Pin('E12'), mosi=Pin('E14'), miso=Pin('A0'))
# DC       - RS/DC data/command flag
# CS       - Chip Select, enable communication
# RST/RES  - Reset
dc  = Pin('E13', Pin.OUT, Pin.PULL_NONE)
cs  = Pin('E11', Pin.OUT, Pin.PULL_NONE)
rst = Pin('E15', Pin.OUT, Pin.PULL_NONE)

lcd_led = Pin('E10', Pin.OUT, Pin.PULL_NONE)
lcd_led.value(1)
Lcd_LEDCount=0
LCD_LEDSet=0

def LCD_LEDCtrl(timer):
    global Lcd_LEDCount,LCD_LEDSet
    Lcd_LEDCount=Lcd_LEDCount+1
    if Lcd_LEDCount == 10:
        Lcd_LEDCount=0
    if LCD_LEDSet > Lcd_LEDCount: lcd_led.value(0)
    else: lcd_led.value(1)

lcd_led_tim = pyb.Timer(2)
lcd_led_tim.init(freq=4000) # Freq: 4KHz
lcd_led_tim.callback(LCD_LEDCtrl)

def LCD_ShowBmp(_tft,FileName):
    f=open(FileName, 'rb')
    print(FileName)
    if f.read(2) == b'BM':  #header
        dummy = f.read(8) #file size(4), creator bytes(4)
        offset = int.from_bytes(f.read(4), 'little')
        hdrsize = int.from_bytes(f.read(4), 'little')
        width = int.from_bytes(f.read(4), 'little')
        height = int.from_bytes(f.read(4), 'little')
        if int.from_bytes(f.read(2), 'little') == 1: #planes must be 1
            depth = int.from_bytes(f.read(2), 'little')
            if depth == 24 and int.from_bytes(f.read(4), 'little') == 0:#compress method == uncompressed
                print("Image size:", width, "x", height)
                rowsize = (width * 3 + 3) & ~3
                if height < 0:
                    height = -height
                    flip = False
                else:
                    flip = True
                w, h = width, height
                if w > 128: w = 128
                if h > 160: h = 160
                tft._setwindowloc((0,0),(w - 1,h - 1))
                for row in range(h):
                    if flip:
                        pos = offset + (height - 1 - row) * rowsize
                    else:
                        pos = offset + row * rowsize
                    if f.tell() != pos:
                        dummy = f.seek(pos)
                    for col in range(w):
                        bgr = f.read(3)
                        _tft._pushcolor(TFTColor(bgr[0],bgr[1],bgr[2]))
            else:
                print(FileName+'is not 24bit pic')

def LCD_ClearScreen():
   tft.fillrect( (0,0), (128,160), TFT.WHITE )

tft=TFT(spi,dc,rst,cs)
tft.init_7735(TFT.REDTAB)
tft.rotation(2)
#LCD_ShowBmp(tft,'WeAct_logo_128_160.bmp')
LCD_ShowBmp(tft,'show1.bmp')
time.sleep(50)
LCD_LEDSet=1
time.sleep(1000)
tft.fill(TFT.WHITE)

a=1232
b=123.45
tft.text((2, 12), str(a), TFT.RED, sysfont,8, nowrap=False)#6--30DANWEI
tft.text((40, 12), str(b), TFT.GREEN, sysfont, 8, nowrap=False)#6--30DANWEI
tft.text((82, 12), '3', TFT.BLUE, sysfont, 8, nowrap=False)#6--30DANWEI
tft.text((40, 62), '+', TFT.BLACK, sysfont, 8, nowrap=False)#6--30DANWEI
#tft.text((15, 110), '321', TFT.BLUE, sysfont, 6, nowrap=False)#6--30DANWEI
tft.text((2, 110), '3', TFT.BLUE, sysfont, 8, nowrap=False)#6--30DANWEI
tft.text((40, 110), '1', TFT.RED, sysfont, 8, nowrap=False)#6--30DANWEI
tft.text((82, 110), '2', TFT.GREEN, sysfont,8, nowrap=False)#6--30DANWEI




sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)

if sensor.get_id() == sensor.OV7725:#OV7725
    sensor.set_hmirror(True)
    sensor.set_vflip(True)

sensor.skip_frames(time = 1000)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.
LCD_ClearScreen()







while(True):
    pyb.delay(10)
    LCD_ShowBmp(tft,'show1.bmp')
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()         # Take a picture and return the image.
    #如果有外部中断1,外部中断2,外部中断3,外部中断4,外部中断5,触发,(下降沿),显示相关信心
#file:///C:/Users/Administrator/AppData/Roaming/OpenMV/qtcreator/html/openmvcam/quickref.html#external-interrupts

    for code in img.find_qrcodes():
        img.draw_rectangle(code.rect(), color = 127)

        print(code)
        disp_str=str(code.payload())#123+656

        tft.text((2, 12), disp_str[0], TFT.RED, sysfont, 8, nowrap=False)#6--30DANWEI
        tft.text((45, 12),disp_str[1], TFT.GREEN, sysfont, 8, nowrap=False)#6--30DANWEI
        tft.text((82, 12), disp_str[2], TFT.BLUE, sysfont, 8, nowrap=False)#6--30DANWEI
        tft.text((40, 62), disp_str[3], TFT.BLACK, sysfont, 8, nowrap=False)#6--30DANWEI
        #tft.text((15, 110), '321', TFT.BLUE, sysfont, 6, nowrap=False)#6--30DANWEI
        tft.text((2, 110), disp_str[4], TFT.BLUE, sysfont, 8, nowrap=False)#6--30DANWEI
        tft.text((45, 110), disp_str[5], TFT.RED, sysfont, 8, nowrap=False)#6--30DANWEI
        tft.text((82, 110), disp_str[6], TFT.GREEN, sysfont,8, nowrap=False)#6--30DANWEI

    print(clock.fps())              # Note: OpenMV Cam runs about half as fast when connected
                                    # to the IDE. The FPS should increase once disconnected.
    #tft.image(0,0,128-1,160-1,img.copy([80,80,128,160]))


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值