EM78P153 RGB LED渐亮渐暗控制器
基本上程序还是DEMO程序,程序并没有采用定时器来生成PWM,而是采用延时循环来实现,这样就做不了其他事情了,但实际上只需要将主循环转换为定时器中断处理即可,很简单.这个是参照市面上邦定IC RGB控制功能来做
的,这应该是采用单片机方案最便宜版本之一了
本程序已经在ICE-153S上仿真通过,实物图片就不提供了,因为整个循环时间约1分钟,照片也不能看到LED渐亮/
暗的效果.
上原理图:
http://cache.amobbs.com/bbs_upload782111/files_10/ourdev_336924.jpg
(原文件名:sch.jpg)
完整程序:
;******************************************
;EM78P153 RGB LED渐亮渐暗控制器
;P5.1-3分别接R G B LED,共七个模式循环R-G-B-RG-BG-RB-RGB
;P6.0 暂停/启动
;P6.1 开/关(并保持关前的状态)
;8M内部时钟,2clocks
;PWM频率约100Hz
;*******************************************
r1 EQU 0X01
R2 EQU 0X02
R3 EQU 0X03
R4 EQU 0x04
IOC5 EQU 0X05
IOC6 EQU 0X06
RF EQU 0x0F
port5 EQU 0X05
port6 EQU 0x06
IOCA EQU 0x0A
IOCB EQU 0X0B
IOCC EQU 0X0C
IOCD EQU 0X0D
IOCE EQU 0X0E
IOCF EQU 0x0F
CONT EQU 0X01
;**************************************
;定义各寄存器
delay EQU 0x20
delay1 EQU 0x21
count_inc EQU 0x22
count_dec EQU 0x23
count_inc_t EQU 0x24
count_dec_t EQU 0X25
sw EQU 0x26
count_modeEQU 0x27;模式寄存器
count_c EQU 0x28;重复脉冲计数器,每个相同脉冲输出5次
count_c_1 EQU 0x29;重复脉冲计数器,每个相同脉冲输出5次
;定义位寄存器
flag_light EQU0
flag_onoff EQU1
c EQU0 ;进位标志位
dc EQU1 ;辅助进位标志
z EQU2 ;零标志位,算术或逻辑操作结果为0时置1
tcif EQU0 ;TCC时间中断标志
icif EQU1 ;P6口输入变化中断标志
exif EQU2 ;外部中断标志
tcie EQU0
icie EQU1
exie EQU2
;*****************************************
org 0x00
jmp start
table:add r2,a
retl @0b00001110 ;RGB灯
retl @0b00001010 ;红蓝灯
retl @0b00000110 ;蓝绿灯
retl @0b00001100 ;红绿灯
retl @0b00000010 ;蓝灯
retl @0b00000100 ;绿灯
retl @0b00001000 ;红灯
;*****************************************
start:
nop
mov a,@0x00
mov sw,a ;初始数据加载
mov a,@0x01 ;0x01
mov count_inc,a ;最小的高电平100us
mov count_inc_t,a
mov a,@0x63 ;0x63
mov count_dec,a
mov count_dec_t,a ;最大高电平时间9.9ms
mov a,@0x05
mov count_c,a ;重复脉冲计数器,每个相同脉冲输出5次
mov count_c_1,a
mov a,@0x07
mov count_mode,a ;七种模式
mov a,@0xff
iowioc6 ;port6为输入口
mov a,@0x00
iow iocb ;所有IO下拉禁止
mov a,@0xff
iow iocc ;漏极开路输出禁止
mov a,@0xf8
iow iocd ;P6.0,1上拉允许
mov a,@0x00 ;
iow ioce
;******************************************************************
main:
call delay100us
jbc port6,1
jmp normal ;P6.1为1,程序正常执行
mov a,@0xff
iowioc5 ;port5为输入口
jmp main ;熄灭LED
normal:
mov a,@0b11110001
iowioc5 ;port5.1-3为输出口
jbc sw,flag_light
jmp night ;标志为1,去渐暗程序
;*******渐亮程序******************
jbc sw,flag_onoff
jmp toon ;标志为0,IO为0,去延时后打开
djz count_inc ;标志为1,IO为1,去延时后关闭
jmp main ;还没到延时时间,就退出
jbs port6,0 ;测试P6.0状态
jmp back_countinc ;为0,需要保持状态, 将count_inc_t数据备份回count_inc
djz count_c
jmp back_countinc ;重复次数
inc count_inc_t ;count_inc_t加1
mov a,count_inc_t
mov count_inc,a ;并将增加后的数据返回count_inc
mov a,@0x05
mov count_c,a ;重复脉冲计数器,每个相同脉冲输出4次
setting_inc:
bs sw,flag_onoff ;LED开的时间够了,关掉
mov a,@0x00
mov port5,a
jmp main
back_countinc:
mov a,count_inc_t
mov count_inc,a
jmp setting_inc
;*****************
toon:
djz count_dec
jmp main ;还没到延时时间,就退出
jbs port6,0 ;测试P6.0状态
jmp back_countdec ;为0,将count_dec_t数据备份回count_dec
djz count_c_1
jmp back_countdec ;没到0,重复次数
mov a,@0x05
mov count_c_1,a
djz count_dec_t
jmp setting_dec
bs sw,flag_light
mov a,@0x63 ;0x63
mov count_inc,a
mov count_inc_t,a
mov a,@0x01 ;0x01
mov count_dec,a
mov count_dec_t,a
jmp main
setting_dec:
mov a,count_dec_t
mov count_dec,a ;并将减去后的数据返回count_dec
bc sw,flag_onoff ;LED关的时间够了,打开
deca count_mode ;加载偏移量
call table
mov port5,a ;输出对应模式
jmp main
back_countdec:
mov a,count_dec_t
mov count_dec,a
jmp setting_dec
;**********************************
night: ;渐暗程序
jbc sw,flag_onoff
jmp toon_1 ;标志为0,IO为0,去延时后打开
djz count_inc ;标志为1,IO为1,去延时后关闭
jmp main ;还没到延时时间,就退出
jbs port6,0 ;测试P6.0状态
jmp back_countinc_1 ;为0,将count_inc_t数据备份回count_inc
djz count_c_1
jmp back_countinc_1
mov a,@0x05
mov count_c_1,a
djz count_inc_t
jmp back_countinc_1
bc sw,flag_light
mov a,@0x01 ;0x01
mov count_inc,a ;最小的高电平时间100us
mov count_inc_t,a
mov a,@0x63 ;0x63
mov count_dec,a
mov count_dec_t,a ;最大高电平时间为9.9ms
djz count_mode
jmp main
mov a,@0x07
mov count_mode,a
jmp main
setting_inc_1:
bs sw,flag_onoff ;
mov a,@0x00
mov port5,a
jmp main
back_countinc_1:
mov a,count_inc_t
mov count_inc,a
jmp setting_inc_1
;*****************
toon_1:
djz count_dec
jmp main ;还没到延时时间,就退出
jbs port6,0 ;测试P6.0状态
jmp back_countdec_1 ;为0,将count_dec_t数据备份回count_dec
djz count_c
jmp back_countdec_1
inc count_dec_t ;为1,count_dec_t加1
mov a,count_dec_t
mov count_dec,a ;并将减去后的数据返回count_dec
mov a,@0x05
mov count_c,a ;重复脉冲计数器,没个相同脉冲输出4
setting_dec_1:
bc sw,flag_onoff ;LED关的时间够了,打开
deca count_mode ;加载偏移量
call table
mov port5,a ;输出对应模式
jmp main
back_countdec_1:
mov a,count_dec_t
mov count_dec,a
jmp setting_dec_1
jmp main
;********************
delay100us:
mov a,@0x1
mov delay,a
delay100us_1:
mov a,@0x39
mov delay1,a
delay100us_2:
djz delay1
jmp delay100us_2
djz delay
jmp delay100us_1
ret
end
烧写代码(晕,居然不能直接上传烧写文件):点击此处下载 ourdev_336925.rar(文件大小:434字节) (原文件名:file.rar) 楼上的大哥咋个弄汇编呢 头晕 但是好像跟51的指令有点像 ELAN的MCU的确便宜。
楼主加油。
QQ:185932251
电子攻城师群:64485187
学习电子技术,共同提升水平,交流工作经验及工作机会! 讲下思路就更好。 用个100us延时,每个PWM波10ms,程序每循环一次,计数寄存器加1,LED逐渐变亮,当计数器由加到99时,LED最亮,开始运行渐暗部分,直至计数器减到1,led最暗,并在软件中判断应该输出那个LED,这里用了查表法来实现不同的模式
并加了端口状态判断,来实现LED渐亮/暗的暂停或关闭功能
PWM频率约100Hz, 这个单片机很有意思哦. 只能烧写一次.
当前我也用了一次, 也是控制一串LED灯, 模式和速度用按钮调节的. 公司里很抠门,不买硬件仿真器,我只好先用软件仿真. 仿真好了就直接烧片子实验. 烧了几个片子后,死活不对劲,还好片子便宜. 后来厚着脸到一家芯片推广公司去在线调试. 才发现一个查表汇编语句只能在放在page0里运行....
后来看到这种分页结构的CPU就有点怕. 这个片子听说只有几毛钱,封装片吗,是真的吗 还有代用的片子呢,更便宜 不錯啊! 目前台湾的OTP单片机我觉最sonix稍为好用点,但产品线没有仪隆的齐全 台系开发工具比较贵,谁能搞出山寨版的就好了? 松翰的开发工具:仿真器+烧录器要1500,的确不便宜啊,仪降信真器是每1种型号1个仿真器,够多的 台系的在开发工具这一块儿是太差劲了。 不过现在像仪隆也开始出了不少的FLASH的芯片了算单的应该只买个烧录器就可以了, 义隆片子小家电用的很多.FLASH的片还没有见过,不知道好不好用. 合泰的开发工具会好用一点。
台系的偶都没用过。公司的很多产品都是用台系的MCU。 请问一下,改变频率是改那里.谢谢 如果公司每个月买的芯片的量足够大,可以向代理商申请免费拿烧录器和仿真器的,我们公司就是这样 乖乖,这样的东西 最好别贴 太乱了。
贴个153头文件
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
; Project Name : Public
; File Name : EM78P153S.dt
;
; Description: EM78P153 Public Program
; Create Date: 2008-3-5
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;
; don't modify the following defin
;-------[ Operational Registers Defin ]-------------------------------------------------------------------------------;
IAR == 0x00 ;[ Indirect Addressing Register ]
TCC == 0x01 ;[ Timer Clock / Counter ]
PC == 0x02 ;[ Program Counter ]
STATUS == 0x03 ;[ Status Register ]
Z_FLAG == 2
AC_FLAG == 1
C_FLAG == 0
RSR == 0x04 ;[ RAM Select Register ]
P5DR == 0x05 ;[ Port5 Data Register ]
P6DR == 0x06 ;[ Port6 Data Register ]
RESERVED0 == 0x07 ;
RESERVED1 == 0x08 ;
RESERVED2 == 0x09 ;
RESERVED3 == 0x0a ;
RESERVED4 == 0x0b ;
RESERVED5 == 0x0c ;
RESERVED6 == 0x0d ;
RESERVED7 == 0x0e ;
ISR == 0x0f ;[ Interrupt Status Register ]
EXTIF equ 2 ;
ICIF equ 1 ;
TCCIF equ 0 ;
;-------[ Special Purpose Registers Defin of Page 0 ]------------------------------------------------------------------;
P0_P5CR == 0x05 ;[ Port5 Control Register ]
P0_P6CR == 0x06 ;[ Port6 Control Register ]
P0_RESERVED0 == 0x07 ;
P0_RESERVED1 == 0x08 ;
P0_RESERVED2 == 0x09 ;
P0_RESERVED3 == 0x0a ;
P0_PDCR == 0x0b ;[ Pull-Down Control Register ]
P0_ODCR == 0x0c ;[ Open-Drain Control Register ]
P0_P6PHCR == 0x0d ;[ P6 Pull-High Control Register ]
P0_WDTCR == 0x0e ;[ WDT Control Register ]
P0_IMR == 0x0f ;[ Interrupt Mask Register ]
EXTMF equ 2 ;
ICMF equ 1 ;
TCCMF equ 0 ;
;=====================================================================================================================;
;=====================================================================================================================;
;-------[ End of the file ]-------------------------------------------------------------------------------------------;
;=====================================================================================================================;
;=====================================================================================================================;
宏定义文件:
; Project Name : InterPhone V3.0
; File Name : Macro_Def.dt
;
; Description: macro define program of InterPhone remote unit
; Create Date: 2008-3-16
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
on_power macro
bs P5DR,3
endm
off_power macro
bc P5DR,3
endm
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
isr_init_tcc macro ;
mov a,@0b00000000 ;reserved
;read only(masked by DISI or hardware)
;set tcc clk source as internal instruction cycle
;tcc as rising edge int
;set pre-scale to tcc
;0
;0
;0--set tcc pre scale as 1:2
contw ;
;---------------------------------------------------------------;
mov a,@TCC_8M_1US2_25US_CNT ;
mov TCC,a ;
;---------------------------------------------------------------;
clr ISR ;reserved
;reserved
;reserved
;reserved
;reserved
;clr ext int request
;clr p6int request
;clt tcc int request
endm ;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
disable_wdt macro ;
wdtc ;
mov a,@0b00000000 ;disable wdt
iow P0_WDTCR ;set p60 as i/o port
;reserved
;reserved
;reserved
;reserved
;reserved
;reserved
endm ;
enable_wdt macro ;
wdtc ;
mov a,@0b10000000 ;enable wdt
iow P0_WDTCR ;set p60 as i/o port
;reserved
;reserved
;reserved
;reserved
;reserved
;reserved
endm ;
;=====================================================================================================================;
;=====================================================================================================================;
;-------[ End of the file ]-------------------------------------------------------------------------------------------;
;=====================================================================================================================;
;=====================================================================================================================;
初始化文件:
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
init_reg: ;
mov a,@0b00000000 ;reserved
mov ISR,a ;reserved
;reserved
;reserved
;reserved
;clr EXTIF
;clr P6ICIF
;clt TCCIF
;---------------------------------------------------------------;
mov a,@0b00000000 ;reserved
iow P0_IMR ;reserved
;reserved
;reserved
;reserved
;mask EXTint
;mask P6IC int
;mask TCCint
;---------------------------------------------------------------;
mov a,@0b00000000 ;disable wdt
iow P0_WDTCR ;set p60 as i/o port
;reserved
;reserved
;reserved
;reserved
;reserved
;reserved
;---------------------------------------------------------------;
mov a,@0b00000000 ;reserved
;read only(masked by DISI or hardware)
;set tcc clk source as internal instruction cycle
;tcc as rising edge int
;set pre-scale to tcc
;0
;0
;0--set pre scale as 1:2
contw ;
;---------------------------------------------------------------;
;---------------------------------------------------------------;0--out mode,1--in mode
mov a,@0b00000000 ;reserved
iow P0_P5CR ;reserved
;reserved
;reserved
;set p53 as out mode(power ctrl)
;set p52 as out mode(unused)
;set p51 as out mode(unused)
;set p50 as out mode(unused)
;---------------------------------------------------------------;
mov a,@0b11110111 ;reserved
mov P5DR,a ;reserved
;reserved
;reserved
;p53 out lowlevel(power ctrl)
;p52 out high level(unused)
;p51 out high level(unused)
;p50 out high level(unused)
;---------------------------------------------------------------;
;---------------------------------------------------------------;0--out mode,1--in mode
mov a,@0b00101001 ;set p67 as out mode(unused)
iow P0_P6CR ;set p66 as out mode(unused)
;set p65 as inmode(osci)
;set p64 as inmode(osco)
;set p63 as inmode(reset)
;set p62 as out mode(unused)
;set p61 as out mode(unused)
;set p60 as inmode(receive pin)
;---------------------------------------------------------------;
mov a,@0b11111111 ;p67 out high level(unused)
mov P6DR,a ;p66 out high level(unused)
;p65 out high level(osci)
;p64 out high level(osco)
;p63 out high level(reset)
;p62 out high level(unused)
;p61 out high level(unused)
;p60 out high level(receive pin)
;---------------------------------------------------------------;
;---------------------------------------------------------------;0--enable pull low,1--disable pull low
mov a,@0b11111111 ;reserved
iow P0_PDCR ;disable p62 pull low fun
;disable p61 pull low fun
;disable p60 pull low fun
;reserved
;disable p52 pull low fun
;disable p51 pull low fun
;disable p50 pull low fun
;---------------------------------------------------------------;0--disable open drain,1--enable open drain
mov a,@0b00000000 ;disable p67 open drain fun
iow P0_ODCR ;disable p66 open drain fun
;disable p65 open drain fun
;disable p64 open drain fun
;disable p63 open drain fun
;disable p62 open drain fun
;disable p61 open drain fun
;disable p60 open drain fun
;---------------------------------------------------------------;0--enable pull high,1--disable pull high
mov a,@0b11111111 ;disable p67 pull high fun
iow P0_P6PHCR ;disable p66 pull high fun
;disable p65 pull high fun
;disable p64 pull high fun
;disable p63 pull high fun
;disable p62 pull high fun
;disable p61 pull high fun
;disable p60 pull high fun(receive pin)
init_reg_end: ;
ret ;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
init_tcc: ;
mov a,@0b00000000 ;reserved
;read only(masked by DISI or hardware)
;set tcc clk source as internal instruction cycle
;tcc as rising edge int
;set pre-scale to tcc
;0
;0
;0--set pre scale as 1:2
contw ;
;---------------------------------------------------------------;
mov a,@TCC_8M_1US2_25US_CNT ;
mov TCC,a ;
;---------------------------------------------------------------;
clr ISR ;reserved
;reserved
;reserved
;reserved
;reserved
;clr ext int request
;clr p6int request
;clt tcc int request
;---------------------------------------------------------------;
mov a,@0b00000001 ;reserved
iow P0_IMR ;reserved
;reserved
;reserved
;reserved
;disable ext int
;disable p6int
;enabletcc int
init_tcc_end: ;
ret ;
;=====================================================================================================================;
;=====================================================================================================================;
;-------[ End of the file ]-------------------------------------------------------------------------------------------;
;=====================================================================================================================;
;=====================================================================================================================;
主程序框架
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
; Project Name : InterPhone V3.0
; File Name : Remote_V30.dt
;
; Description: main program of InterPhone remote unit
; Create Date: 2008-3-16
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
include "EMC78P153S.dt"
include "Macro_Def.dt"
include "Const_Def.dt"
include "Var_Def.dt"
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
org 000h
jmp rst_isr
org 008h
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
tcc_isr:
mov a_bak,a
swapa STATUS
mov status_bak,a
isr_init_tcc
wdtc
; call test_tcc
call remote
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
wakeup_not_over:
cnt1_isr_end:
swapa status_bak
mov STATUS,a
mov a,a_bak
reti
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
rst_isr:
disi
call init_reg
call init_rst_var
call init_tcc
enable_wdt
eni
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
main:
main_lp:
jmp main_lp
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
;=====================================================================================================================;
include "Data.dt"
include "Sys.dt"
include "Test.dt"
org 0x300
include "Remote.dt"
org 0x400
;=====================================================================================================================;
;=====================================================================================================================;
;-------[ End of the file ]-------------------------------------------------------------------------------------------;
;=====================================================================================================================;
;=====================================================================================================================;
仅供参考。 呵呵,楼主查表是用ADD吧?这样的话只能放在每个PAGE的前256字节,如果用TBL的话,就可以放在任意空间了。 回复【21楼】qeh7510
-----------------------------------------------------------------------
EM78P153好像没有TBL指令. mark bill 楼主 现在小弟也在做仪隆单片机的开发,想联系联系你,小弟的QQ:1063296501 请问这个RGB的LED是什么型号?大概多少钱一个? mark mark 回复【7楼】chendaon 嘛糖人
-----------------------------------------------------------------------
是真的。 程序页在C语言中是怎么切换的? 汇编看着就蛋疼 mark 专用烧录器,不利于学习 bill 发表于 2008-7-28 22:09 static/image/common/back.gif
用个100us延时,每个PWM波10ms,程序每循环一次,计数寄存器加1,LED逐渐变亮,当计数器由加到99时,LED最亮,开 ...
这样做并不是最好的.LED的亮度等级只有一百个等级.
在大功率LED的时候会发生抖动暗闪的情况.
这个8脚的片子做250等级的三色渐变都能做出来.只是程序不方便贴出来,毕竟这是给人家做的产品.
BSR LED
MOVR LED_SPEED,0
SUBAR TMR0,0
BTRSS STATUS,C
LGOTO $-3
BCR LED
这是佑华的指令.思路如下/
PWM周期=定时器定时时间
点亮时间=0到LED_SPEED的值(需要设置led_speed值在0-250之间循环变化)
熄灭时间=led_speed的值到定时器结束. 楼上,,说的对啊,,受教了!! 我也做过一个类似的,也是控制三色灯渐变的,是用软件模PWM进行控制,过程中还能实时按键检测,还可以干其它的事情。定时器用了,但是是用作程序的时序控制。功能多很多,但程序好像比楼主的还要短小。我没细看楼主的程序,只看了楼主的说明。目前这个产品已经量产多年了,我当时是用PIC12F508开发程序,然后将烧写码转换,用8p53的台系芯片,几毛钱一块。
由于产品是以前公司的,所以我不能将程序帖上来。需要的可以一起交流。我现在做的产品,暂时都与LED的控制有关,就是的控制LED的模式之类。目前用LGT08A芯片。花了一天时间去熟悉这芯片,花了一天时间写好程序的框架,花了两天时间将闪灯的模式做成表格,以后增加模式,换模式,只需简单修改一下数据表就行。 sballbobo 发表于 2013-7-6 17:27
我也做过一个类似的,也是控制三色灯渐变的,是用软件模PWM进行控制,过程中还能实时按键检测,还可以干其 ...
老兄,你好,目前也有一个案子需要弄这个RGBLED的,方便的话跟你请教一下这个RGB控制思路。。 最便宜,不存在的 lin135 发表于 2009-3-6 12:07
目前台湾的OTP单片机我觉最sonix稍为好用点,但产品线没有仪隆的齐全
上主页一查,发现sonix也有flash的8051单片机,不知是针对ST8MS003吗?价格好吗?好采购吗?
另外看到sonix和笙泉都有ARM的单片机了,又多个选择了,
页:
[1]