打印

用PIC单片机做的白噪声产生

[复制链接]
2053|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zhangmangui|  楼主 | 2013-6-17 11:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
下面是汇编的代码   又能看懂的帮忙翻译一下   确认一下是否可行  谢啦
title  "White Noise Generator"
;
;  Tom Wiltshire for Elecric Druid, March 2008
;
;  This program provides a replacement for the notorious
;  MM5837 digital noise source chip. It provides pure
;  white noise by outputting random bits at >90KHz.
;  This gives a pure noise spectrum to well above audio
;  range (3dB dip at 45KHz).
;
;  Hardware Notes:
;   PIC12F675 running at 4 MHz using internal clock
;
;  The hardware is very simple. There are no inputs.
;
; One output
;   GP4: NOISE output

        list      p=12f675           ; list directive to define processor
        #include <p12f675.inc>        ; processor specific variable definitions

        errorlevel  -302              ; suppress message 302 from list file

        __CONFIG   _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT


;------------------------------
;        Variables
;------------------------------

CBLOCK 0x020

        ; LFSR 1, a 31-bit register
        LFSR1_1
        LFSR1_2
        LFSR1_3
        LFSR1_4
        ; LFSR 2, a 23-bit register
        LFSR2_1
        LFSR2_2
        LFSR2_3
        ; Temporary storage
        TEMP
ENDC

;-------------------------------------
;        DEFINE STATEMENTS
;-------------------------------------

; Useful bit definitions for clarity       
#define ZEROBIT                STATUS,Z        ; Zero Flag
#define CARRY                STATUS,C        ; Carry Flag
#define BORROW                STATUS,C        ; Borrow is the same as Carry


;----------------------------------------------------------------------
; Begin Executable Code Segment
;----------------------------------------------------------------------
        org     0x000                ; processor reset vector
        goto        Main                ; Avoid the interrupt vector

;        org     0x004           ; interrupt vector location
Main:
; Do the setting up               
        bsf        STATUS, RP0        ; Bank 1
;        call        0x3FF                ; Retrieve factory calibration value
;        movwf   OSCCAL                ; Store cal value
        clrf        ANSEL                ; Turn off analog inputs
        movlw   b'101111'        ; GP4 Output, all others unused inputs
        movwf   TRISIO

        bcf        STATUS, RP0        ; Bank 0
        clrf        GPIO
        movlw        0x07
        movwf        CMCON

        ; Set up initial values of the registers
        movlw        0x45
        movwf        LFSR1_1
        movlw        0x57
        movwf        LFSR1_2
        movlw        0x9F
        movwf        LFSR1_3
        movlw        0xF2
        movwf        LFSR1_4
        movlw        0xD7
        movwf        LFSR2_1
        movlw        0xC8
        movwf        LFSR2_2
        movlw        0x79
        movwf        LFSR2_3

MainLoop:

;        movlw        0x3F
;        movwf        GPIO

;        movlw        0xFF
;        movwf        TEMP
;DelayLoop:
;        nop
;        nop
;        decfsz        TEMP, F
;        goto        DelayLoop

;        clrf        GPIO

;        movlw        0xFF
;        movwf        TEMP
;DelayLoop2:
;        nop
;        nop
;        decfsz        TEMP, F
;        goto        DelayLoop2

;        goto        MainLoop



; 31-bit LFSR with taps at 31 and 28
;----------------------------------------------------

        swapf        LFSR1_4, W        ; Get bit 28
        movwf        TEMP
        rlf        LFSR1_4, W        ; Get bit 31
        xorwf        TEMP, F
        ; Shift the XORd bit into carry
        rlf        TEMP, F
        ; Shift the register
        rlf        LFSR1_1, F
        rlf        LFSR1_2, F
        rlf        LFSR1_3, F
        rlf        LFSR1_4, F
        ; Output the noise bit
        movf        LFSR1_1, W
        movwf        GPIO


; 21-bit LFSR with taps at 21 and 19
;----------------------------------------------------
       
        rrf        LFSR2_3, W        ; Get bit 19
        movwf        TEMP
        rrf        TEMP, F
        swapf        LFSR2_3, W        ; Get bit 21
        xorwf        TEMP, F
        ; Shift the XORd bit into carry
        rrf        TEMP, F
        ; Shift the register
        rlf        LFSR2_1, F
        rlf        LFSR2_2, F
        rlf        LFSR2_3, F
        ; Output the noise bit
        movf        LFSR2_1, W
        movwf        GPIO

        goto        MainLoop

; We never reach here
        end
沙发
wangch_sh| | 2014-9-9 15:36 | 只看该作者
汇编代码看起来很费劲的

使用特权

评论回复
板凳
yewuyi| | 2014-9-9 16:11 | 只看该作者
LZ这个像是反汇编的代码。

白噪声要结合硬件,纯粹的软件运算弄不出白噪声。

使用特权

评论回复
地板
zhimagod| | 2014-9-9 17:33 | 只看该作者
这个看起来就是把一串数组一位一位发送出去……

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:欢迎进入【TI DSP 论坛】 & 【DSP 技术】           TI忠诚粉丝!

934

主题

26373

帖子

585

粉丝