• slider image 442
  • slider image 477
  • slider image 479
  • slider image 480
  • slider image 481
  • slider image 482
:::


Browsing this Thread:   1 Anonymous Users






Re: dsPIC30F6014的RS232傳送單一字元
#5
版主
版主


查看用戶資訊
剪貼過去的程式空隔都變了樣,有要原稿 e-mail 過來吧 !

taiwan.techhelp@microchip.com

發表於: 2004/7/9 10:32
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: dsPIC30F6014的RS232傳送單一字元
#4
版主
版主


查看用戶資訊
送一段RS-232與A/D的範例程式參考看看:

.equ __30F6014, 1
.include "C:\Program Files\MPLAB IDE\dsPIC_Tools\support\inc\p30f6014.inc"


;------------------------------------------------------------------------------
;Program Specific Constants (literals used in code)

.equiv FCY, 1000000 ;Instruction Cycle Frequency
.equiv BAUDRATE, 2400 ;Operating Baud Rate
.equiv DelayConst, FCY/2000


;------------------------------------------------------------------------------
;Global Declarations:

.global __reset ;Declare the label for the start of code
.global __U1TXInterrupt ;Declare USART1 TX ISR name global



;
;Assign ram space for register Flag
.section .nbss
.align 2
DelayReg: .space 2

;------------------------------------------------------------------------------
;Code Section in Program Memory

.text ;Start of Code section


__reset:
mov #__SP_init, W15 ;Initalize the Stack Pointer
mov #__SPLIM_init, W0
mov W0,SPLIM ;Initialize the Stack Pointer Limit Register
nop ;Add NOP to follow SPLIM initialization
clr W0 ;Initialize Working registers to 0x0000
mov W0,W14 ;clr working registers w0 to w14
repeat #12
mov W0,[++W14]
clr W14

;------------------------------------------------------------------------------

RCALL InitADC12 ; Initialize the ADC
RCALL Init_USART1 ;initialize USART1 for Tx interrupt at 2400 baud

Again:
bset ADCON1,#SAMP ; start sampling ...
mov #10,w0 ; delay for
mov w0,DelayReg ; for 10 mS
rcall DelayNmSec ; /
bclr ADCON1,#SAMP ; start Converting
ADCdone:
btss IFS0,#ADIF ; conversion done?
bra ADCdone ; no then keep checking
rcall SendADC ; Load buffer and transmit
bra Again ;repeat again

;
;-----------------------------------------------------------------------------

;Subrotuinte to Init Ports pins connected to LED1 to LED4

;------------------------------------------------------------------------------

Init_PORTS:

clr LATD
mov #0xFF0F,W0 ; set RD7 to RD4 as outputs
mov W0,TRISD
return
;
;InitUSART1, subroutine initializes the USART
;
;
Init_USART1:
clr U1MODE
clr U1STA
bset U1MODE, #UARTEN ;Enable UART (implies reception)
mov #(((FCY/BAUDRATE) / 16) - 1), w0
mov w0, U1BRG ;Initialize BRG

bclr IFS0, #U1TXIF ;Clear the interrupt flag
bclr IEC0, #U1TXIE ;Disable ISR processing
bset U1STA, #UTXEN ;Enable Transmission
return
;
;
;*******************************************************************
; Below is the code required to setup the ADC registers for :
; 1. 1 channel conversion (in this case RB2/AN2)
; 2. Manual Sample start
; 3. User specified sampling delay (100mS in this case)
; 4. Manual Stop Sampling and start converting
; 5. Manual check of Conversion complete
;
; The code is as per Figure 18-3 in the Ref. manual
;*********************************************************************
InitADC12:

mov #0xfffb,w0 ;all PORTB = Digital; RB2 = analog
mov w0,ADPCFG
clr ADCON1 ; SAMP bit = 0 ends sampling ...
; and starts converting
mov #0x0002,w0 ; Connect RB2/AN2 as CH0 input ..
mov w0,ADCHS ; in this example RB2/AN2 is the input
clr ADCSSL
mov #0x0002,w0 ; Manual Sample, Tad = internal 2 Tcy
mov w0,ADCON3
clr ADCON2
bset ADCON1,#ADON ; turn ADC ON
return
;
;------------------------------------------------------------------------------
;DelayNmSec, delays the value in the DelayReg in mSecs at a given Mip rate
;
DelayNmSec:
do #DelayConst,DIL
nop
DIL: nop
dec DelayReg
bra nz,DelayNmSec
return
;
;-----------------------------------------------------------------------------
;SendADC, sends 5 charaters to the U1TXREG buffer for transmission. The
;first 3 values are the hex code for the 12 bit ADC value. The last two are
;the CR and LF characters
;
SendADC:
mov ADCBUF0,w0 ;get ADC value
swap w0 ;swap low and high bytes
rcall GetAscii ;get the ascii value
rcall LoadAscii ;load the ascii value
mov ADCBUF0,w0 ;get ADC value
swap.b w0 ;swap low and high nibbles of LSB
rcall GetAscii ;get Ascii value
rcall LoadAscii ; load ascii value
mov ADCBUF0,w0 ;get ADC value
rcall GetAscii ;get ascii value
rcall LoadAscii ;load ascii value
mov #0x000A,w0 ;load a CR
rcall LoadAscii ; /
mov #0x000D,w0 ;load LF
rcall LoadAscii ;
return
;
;GetAscii, takes the value in w0 and uses the 4 LS bits and
;converts them to a hex value (0 to F) in w0. Next it
;converts the hex value in w0 to an ascii displayable character
GetAscii:
mov #0x000F,w1 ;mask all but the low 4 bits
and w0,w1,w0 ; /
cp.b w0,#10 ;compare with 10
bra n,Add30hex ;< 10 the add 30 hex
add #0x37,w0 ;>= 10 then add 0x37 to make into ascii
; character (A to F)
return
Add30hex:
add #0x30,w0 ;add 0x30 to make ascii number (0 to 9)
return
;
;LoadAscii, takes the ascii value in w0 and loads it into
;the U1RXBUF if there is room in the buffer.
LoadAscii:
btsc U1STA,#UTXBF ;buffer empty then skip
bra LoadAscii ; keep looking if full
mov w0,U1TXREG ;load the buffer
return
;



;------------------------------------------------------------------------------

.end ;End of code in this file


發表於: 2004/7/9 9:59
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: dsPIC30F6014的RS232傳送單一字元
#3
新會員
新會員


查看用戶資訊
其它的設定我能確定都ok,因為我可以從終端機傳送一字元出去後再從PIC端將此字元回傳至終端機。但就是在只想傳送單一字元時,都不能正常工作。

發表於: 2004/7/8 10:33
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: dsPIC30F6014的RS232傳送單一字元
#2
高級會員
高級會員


查看用戶資訊
看看傳送鮑率的設定是否相同 , 在終端機還會show出? , 表示終端應該有收到東西 , 只是看不懂而已 ,

發表於: 2004/7/8 9:42
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


dsPIC30F6014的RS232傳送單一字元
#1
新會員
新會員


查看用戶資訊
我想請問一下,用組合語言在做RS232通訊時,
想連續傳送一個字元,例如傳送字元'1',該怎麼寫組語呢?
我在程式中寫了

mov #0x0031,w0
mov w0,U1TXREG

結果在終端機上看到的全都是'?’

這是為什麼呢?

發表於: 2004/7/7 21:01
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------