|
|||||||||||
| 技術(shù)交流 | 電路欣賞 | 工控天地 | 數(shù)字廣電 | 通信技術(shù) | 電源技術(shù) | 測控之家 | EMC技術(shù) | ARM技術(shù) | EDA技術(shù) | PCB技術(shù) | 嵌入式系統(tǒng) 驅(qū)動(dòng)編程 | 集成電路 | 器件替換 | 模擬技術(shù) | 新手園地 | 單 片 機(jī) | DSP技術(shù) | MCU技術(shù) | IC 設(shè)計(jì) | IC 產(chǎn)業(yè) | CAN-bus/DeviceNe |
跟我學(xué)---軟件模擬PWM |
| 作者:scb521 欄目:單片機(jī) |
可能很多人都用軟件模擬過不少東西,比如IIC,SPI,UART等. 但我相信用軟件模擬PWM的人應(yīng)該還不多,因?yàn)橐话愕腜WM都要求不斷的輸出. 這樣就非常占用CPU的資源. 然而,當(dāng)你利用我們的多核MCU時(shí),你就會(huì)不再吝嗇 CPU的資源了,因?yàn)榧词鼓阌玫粢粋(gè),都還有7個(gè)任你使用呢,這樣的效果我想傳統(tǒng)的 MCU還沒有那家的可以靈活. 一個(gè)14PIN的MCU就可以方便完成你想要的I/O操作了喲 看看我模擬的PWM原程序,是不是還有7個(gè)CPU在等待任務(wù)呢: 歡迎點(diǎn)擊下載閱讀: |
| 2樓: | >>參與討論 |
| 作者: scb521 于 2007/3/9 20:24:31 發(fā)布:
//*************************************************************************** // Example NAME :: PWM_Generator( ) Version 1.00 // MODULE NAME :: PWM.asm // MCU TYPE :: PDK80C02 // OSC :: External (HT) 8MHZ // Abstract: // MODULE related to PWM generator // Environment: // PADAUK FPPA(TM) IDE Tool Version : 0.12 Beta // // Revision History: // Sep. 19, 2006 Raker.Yang Created ///////////////////////////////////////////////////////////////////////// // COPYRIGHT (C) 2006 by ChangKe Electronic TECHNOLOGY Co. Ltd. All rights reserved. ; ;--------special register define--------------------- flag.z equ flag.0 flag.c equ flag.1 flag.ac equ flag.2 flag.ov equ flag.3 ;--------special register define end----------------- ; |
|
| 3樓: | >>參與討論 |
| 作者: scb521 于 2007/3/9 20:26:38 發(fā)布:
;---------constant define----------------------------- ;FPPA0~FPPA7 stack bottom define------- STACK_BOTTOM0 equ 0x7F STACK_BOTTOM1 equ 0x79 STACK_BOTTOM2 equ 0x73 STACK_BOTTOM3 equ 0x6D STACK_BOTTOM4 equ 0x69 STACK_BOTTOM5 equ 0x65 STACK_BOTTOM6 equ 0x61 STACK_BOTTOM7 equ 0x5D ;-------------------------------------- ; ;---------PWM VAL defien----------------------------- PWM_FREQH0 equ 0x05 PWM_FREQL0 equ 0x04 PWM_DUTYH0 equ 0x02 PWM_DUTYL0 equ 0x02 ;--------I/O PORT define----------------------------- PWMOUT0 equ pa.2 PWMOUT1 equ pa.3 PWMOUT2 equ pa.4 RX0 equ pb.6 ;--------I/O PORT defien end------------------------- ;----------PROGRAM FOLLOWING------------------------------------ ; |
|
| 4樓: | >>參與討論 |
| 作者: scb521 于 2007/3/9 20:28:30 發(fā)布:
;---------constant define----------------------------- ;FPPA0~FPPA7 stack bottom define------- STACK_BOTTOM0 equ 0x7F STACK_BOTTOM1 equ 0x79 STACK_BOTTOM2 equ 0x73 STACK_BOTTOM3 equ 0x6D STACK_BOTTOM4 equ 0x69 STACK_BOTTOM5 equ 0x65 STACK_BOTTOM6 equ 0x61 STACK_BOTTOM7 equ 0x5D ;-------------------------------------- ; ;---------PWM VAL defien----------------------------- PWM_FREQH0 equ 0x05 PWM_FREQL0 equ 0x04 PWM_DUTYH0 equ 0x02 PWM_DUTYL0 equ 0x02 ;--------I/O PORT define----------------------------- PWMOUT0 equ pa.2 PWMOUT1 equ pa.3 PWMOUT2 equ pa.4 RX0 equ pb.6 ;--------I/O PORT defien end------------------------- ;----------PROGRAM FOLLOWING------------------------------------ ; |
|
| 5樓: | >>參與討論 |
| 作者: scb521 于 2007/3/9 20:32:39 發(fā)布:
.include "pwm_generator.inc" .ramadr 0x00 ; int freqH0 int freqL0 int freqL0buf ; int freqHbuf0 ; int dutyH0 int dutyL0 ; int dutyHbuf0 int dutyL0buf ;.romadr 0 //===================================================== //--- //--- Program Begin goto reset ; //fpp0boot ;// Processor #0 entry vector goto fpp1boot ; // Processor #1 entry vector goto fpp2boot ; // Processor #2 entry vector goto fpp3boot ; // Processor #3 entry vector goto fpp4boot ; // Processor #4 entry vector goto fpp5boot ; // Processor #5 entry vector goto fpp6boot ; // Processor #6 entry vector goto fpp7boot ; // Processor #7 entry vector |
|
| 6樓: | >>參與討論 |
| 作者: scb521 于 2007/3/9 20:34:06 發(fā)布:
//------------------------------------------------------------------------ ; .include "reset.asm" //--- Boot-up the chip use Processor-0 here! reset: mov a, STACK_BOTTOM0 mov sp, a call clkModeSelect call ioInit call ramClear pmode 0x01 ;----------FPP0 program---------------------------------- ;PWM generator ;argument: T = (11 + 11*(freqL0)) * t = 11*(1 + (freqL0)) * t ; Duty = (11 + 11*(dutyL0)) * t = 11*(1 + (dutyL0)) * t ; IF (dutyL0) = 0, THEN OUTPUT low level constantly ; IF (dutyL0) >= (freqL0) + 1, THEN OUTPUT High level constantly ; Note: t is fpp0's SYSTEM clock,duty VALUE must be less than T VALUE. ;------------------------------------ |
|
| 7樓: | >>參與討論 |
| 作者: scb521 于 2007/3/9 20:37:47 發(fā)布:
fpp0boot: mov a, PWM_FREQL0 mov freqL0, a mov a, PWM_DUTYL0 mov dutyL0, a mov a, 0xff mov fppen, a fpp0Loop: pwm0Init: mov a, freqL0 ;trace1_7 mov freqL0buf, a ;trace1_8 mov a, dutyL0 ;trace1_9 mov dutyL0buf, a ;trace1_10 pwm0start: mov a, dutyL0buf ;trace1_11 t1sn flag.z ;trace0_0 goto dec_duty0_reg ;trace0_1 set0 PWMOUT0 ;trace1_1 nop ;trace1_2 goto check_pwm0_freq ;trace1_3 dec_duty0_reg: set1 PWMOUT0 ;trace0_2 dec dutyL0buf ;trace0_3 check_pwm0_freq: mov a, freqL0buf ;trace0_4 t0sn flag.z ;trace0_5 goto pwm0Init ;trace1_6 ;dec frequnce reg nop ;trace0_6 nop nop dec freqL0buf ;trace0_9 goto pwm0start ;trace0_10 ;--------the end of fppa 0------------------ ; ;--------fppa 1 program--------------------- |
|
| 8樓: | >>參與討論 |
| 作者: scb521 于 2007/3/9 20:39:52 發(fā)布:
fpp0boot: mov a, PWM_FREQL0 mov freqL0, a mov a, PWM_DUTYL0 mov dutyL0, a mov a, 0xff mov fppen, a fpp0Loop: pwm0Init: mov a, freqL0 ;trace1_7 mov freqL0buf, a ;trace1_8 mov a, dutyL0 ;trace1_9 mov dutyL0buf, a ;trace1_10 pwm0start: mov a, dutyL0buf ;trace1_11 t1sn flag.z ;trace0_0 goto dec_duty0_reg ;trace0_1 set0 PWMOUT0 ;trace1_1 nop ;trace1_2 goto check_pwm0_freq ;trace1_3 dec_duty0_reg: set1 PWMOUT0 ;trace0_2 dec dutyL0buf ;trace0_3 check_pwm0_freq: mov a, freqL0buf ;trace0_4 t0sn flag.z ;trace0_5 goto pwm0Init ;trace1_6 ;dec frequnce reg nop ;trace0_6 nop nop dec freqL0buf ;trace0_9 goto pwm0start ;trace0_10 ;--------the end of fppa 0------------------ ; ;--------fppa 1 program--------------------- |
|
| 9樓: | >>參與討論 |
| 作者: scb521 于 2007/3/9 20:41:57 發(fā)布:
;--------fppa 5 program--------------------- fpp5boot: mov a, STACK_BOTTOM5 mov sp, a fpp5loop: nop goto fpp5loop ;--------the end of fppa 5------------------ ; ;--------fppa 6 program--------------------- fpp6boot: mov a, STACK_BOTTOM6 mov sp, a fpp6loop: nop goto fpp6loop ;--------the end of fppa 6------------------ ; ;--------fppa 7 program--------------------- fpp7boot: mov a, STACK_BOTTOM7 mov sp, a fpp7loop: nop goto fpp7loop ;--------the end of fppa 7------------------ ; |
|
| 10樓: | >>參與討論 |
| 作者: scb521 于 2007/3/9 20:42:53 發(fā)布:
;------------------------------------------------------------------- ;NAME :clkModeSelect ;Input :void ;OUTPUT : ;TEMP reg :void ;Function :SELECT SYSTEM clock: exteral OSC, ;Argument : ;-------------------------------------------------------------- clkModeSelect: set0 clkmd.1; // turn-off watchdog //------Low clock SWITCH to High clock--------------------------------------- mov a, 0x00; mov eoscr, a; //External OSCillator Register // bit-0: 1=Enable XTAL Smith trigger strong mode // 0=Disable XTAL Smith trigger strong mode // bit-1: 1=Enable XTAL Smith trigger // 0=Disable XTAL Smith trigger // bit4-2: Option of driving strength in CRYSTAL oscillator // bit6-5: 00=External RC oscillator // 01=32KHZ CRYSTAL oscillator // 10=4MHZ CRYSTAL oscillator // 11=20MHZ CRYSTAL oscillator // bit7: 1=Enable external RC oscillator or CRYSTAL oscillator // 0=Disable external RC oscillator or CRYSTAL oscillator // delay 0xff; // internal 32KHZ need delay 30m/S // external 20MHZ need delay 1m/S mov a, 0x00 ; mov ihrcrh, a; //bit-0:Internal high RC mov a, 0xCA; mov ihrcrl, a; // 12MHz/clkmd bit7~5/Pmode/instruction=real clock delay 255 ; // 1T=12MHz/4/8=375KHz (2.6uS) |
|
| 11樓: | >>參與討論 |
| 作者: scb521 于 2007/3/9 20:46:15 發(fā)布:
;------------------------------------------------------------------- ;NAME :clkModeSelect ;Input :void ;OUTPUT : ;TEMP reg :void ;Function :SELECT SYSTEM clock: exteral OSC, ;Argument : ;-------------------------------------------------------------- clkModeSelect: set0 clkmd.1; // turn-off watchdog //------Low clock SWITCH to High clock--------------------------------------- mov a, 0x00; mov eoscr, a; //External OSCillator Register // bit-0: 1=Enable XTAL Smith trigger strong mode // 0=Disable XTAL Smith trigger strong mode // bit-1: 1=Enable XTAL Smith trigger // 0=Disable XTAL Smith trigger // bit4-2: Option of driving strength in CRYSTAL oscillator // bit6-5: 00=External RC oscillator // 01=32KHZ CRYSTAL oscillator // 10=4MHZ CRYSTAL oscillator // 11=20MHZ CRYSTAL oscillator // bit7: 1=Enable external RC oscillator or CRYSTAL oscillator // 0=Disable external RC oscillator or CRYSTAL oscillator // delay 0xff; // internal 32KHZ need delay 30m/S // external 20MHZ need delay 1m/S mov a, 0x00 ; mov ihrcrh, a; //bit-0:Internal high RC mov a, 0xCA; mov ihrcrl, a; // 12MHz/clkmd bit7~5/Pmode/instruction=real clock delay 255 ; // 1T=12MHz/4/8=375KHz (2.6uS) |
|
| 12樓: | >>參與討論 |
| 作者: scb521 于 2007/3/9 20:51:12 發(fā)布:
// mov a, r01; // set1 pa, led1; // set1 pa.1; mov a, 0x14 //;0x64 ;0x14; //14; //e4 //54 mov clkmd, a; // Internal Low RC, Watch Dog disable, // bit-0: Reset Function // bit-1: 1=Enable Watch Dog (default) // 0=Disable Watch Dog // bit-2: 1=Enable Internal Low RC (default) // 0=Disable Internal Low RC // bit-3: No used // bit-4: 1=Enable Internal High RC (default) // 0=Disable Internal High RC // bit-7~5: 000=internal high RC/4 // 001=internal high RC/2 // 010=internal high RC // 011=external OSC/4 // 100=external OSC/2 // 101=external OSC // 110=internal low RC/4 // 111=internal low RC (default) ret ;--------------------------------------------------------------------------------------------- ; ;-----------IO initial------------------------------------------------------------------------ ;Input :void ;OUTPUT :void ;TEMP reg :void ;Function :I/O direction initial ;Argument :0--->input; 1--->OUTPUT ;------------------------------------------------------ ioInit: //---Assign PA.0 is IR_Input mov a, 0x1c ; // PA.0:IR mov pac, a ; // mov a, 0x00 ; mov pa, a ; //---- ALL of PORT B assign as LCM Data Bus PORT |
|
| 13樓: | >>參與討論 |
| 作者: scb521 于 2007/3/9 20:53:12 發(fā)布:
mov a, 0x00 ; // define the PB CONTROL property mov pbc, a ; // PB input mov a, 0xff ; // assign PB.6 PORT UART RX mov pb, a ; // ret ;------------IO initial end-------------------------------------------------- ; ;------------Ram clear------------------------------------------------------- ;NAME :ramClear ;Input :const(reset stack bottom) ;OUTPUT :void ;TEMP reg :void ;Function : ;Argument : ;------------------------------------------------------ ramClear: ; mov a, STACK_BOTTOM - 4; ; mov lb@RAMindex, a; ; mov a, 0x00; ; mov hb@RAMindex, a; ;ClearRAMLoop: ; wdreset; ; idxm RAMindex, a; ; dzsn lb@RAMindex; ; goto ClearRAMLoop; ret |
|
| 14樓: | >>參與討論 |
| 作者: LB 于 2007/3/9 21:28:51 發(fā)布:
暈!居然沒有人頂! |
|
| 15樓: | >>參與討論 |
| 作者: …風(fēng)… 于 2007/3/15 13:50:47 發(fā)布:
寫程序沒註解,頂什么。 |
|
| 16樓: | >>參與討論 |
| 作者: fengspark 于 2007/3/24 13:22:43 發(fā)布:
謝謝樓主共享資料 |
|
|
|
| 免費(fèi)注冊為維庫電子開發(fā)網(wǎng)會(huì)員,參與電子工程師社區(qū)討論,點(diǎn)此進(jìn)入 |
Copyright © 1998-2006 m.58mhw.cn 浙ICP證030469號 |