• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::

論壇索引


Board index » All Posts (Ryang)




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


送一段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
頂部


Re: 請問dsPIC有除法嗎??
版主
版主


從組合語言的指令來看 : 供有五個除法指令
DIV.S -- 有號數 16/16 整數除法
DIV.SD -- 有號數 32/16 整數除法
DIV.U-- 無號數 16/16 整數除法
DIV.UD --無號數 32/16 整數除法
DIV F --小號 16/16 整數除法

如用C語言小數點的計算就很簡單,先需告為浮點數,如下所示:
float A=5.123;
float B=2.111;
flaot C,D;

C=A*B;
D=A/B;


發表於: 2004/7/9 9:46
頂部


Re: 使用c18定義時#define常數的疑問及pragma romdata疑問
版主
版主


const 是用來定義不會被改變的數一般稱之為常數,在Hi-Tech PICC 及 C18裡,常用來宣告它是存放在 Flash ROM 的查表值,例如 lcd顯示的固定字串,SIN Table ...等固定不變的資料。記住它實際佔有記憶空間的。

#define 是定義以文字取代常數、數值、變數或 I/O位址...等,簡單而言就是以文字取代,編譯時不占記憶空間的,即使是取代變數也是你在宣告變數時佔用記憶空間,與#define無關。

發表於: 2004/7/8 21:51
頂部


Re: 使用c18定義時#define常數的疑問及pragma romdata疑問
版主
版主


#define 的用意是用一個好記有意義的文字去取代一個數字、常數及文字。
用法如下:
#define KEY_SW1 PORTAbits.RA0
#define Baud_Rate 4000000/(51+1)

if (KEY_SW1) PORTB=0x00 ;

再寫程式中就可以用KEY_SW1來取代PORTA的RA0簡單又好記
程式也比較容易讀。

發表於: 2004/7/8 14:05
頂部


Re: 關於16F630
版主
版主


PIC16F630實際Flash memory是1024 x 14-bit換算成byte的容量為 1024 Bytes +1204 (6/8) bytes = 1792 bytes

發表於: 2004/7/7 17:16
頂部


Re: 再問大家及版主一些pic的英文另外加問指令的問題謝謝
版主
版主


table pointer是否可稱作查表指標囉?
在PIC18Fxxxx系列因為可以直接利用指標進行flash memory的讀寫,又因18F可以定址到2Mbytes所以就用三個指位器來訂ROM的位址。
TBLPTRU (b23:b16) , TBLPTRH (b15:b8) , TBLPTRL (b7:b0)的位址設定好了以後就可以用TBLRD*的指令讀取ROM資料,詳情請參考Data Sheet 讀五章之說明。


bootloader是什麼?
程式分為兩段,一為Bootloader,另一為主程式。主程式可透過RS-232 , I2C .... 等介面寫成得Bootloader功能利用自我燒錄的機制即時更新主程式。

usart中有提到一個LIN這是什麼東西?
LIN = Local Interconnect Networking 簡稱LIN Bus,常用於汽車裡簡單的電裝品控制。複雜的會用CAN Bus

acquisition time 代表什麼時間?
A/D 的 Acqusition Time = AMplifier Settling Time + Holding Capacitor Charging Time + Temperature Coefficient
就是取樣時間啦。詳情請參考 Data Sheet TABLE 20-3

power up字面上意思是電源起動上升?

電源打開

cycle-by-cycle 涵意知道,可是真的查不到怎麼翻譯

????

另外指令中的BN BNC等等
它字面上的BRANCH是代表?..OPERATION寫著PC+2+2N
2N是指什麼

以 BNC ABC ==>(PC+ 2N)
BRA CDE ==>(PC+2)
條件成立(C=0)跳到ABC執行
條件不成立(C=1)跳到CDE執行


發表於: 2004/7/7 17:09
頂部


Re: dsPIC30f2010組譯完成後ㄉ問題...
版主
版主


dsPIC30F6014是80-pin的IC,而dsPIC30F2010只有28-pin所以你的程式就必須修改以符合I/O及週邊的需求。所以先修改PORTD,PORTA的腳位以符合30F2010的腳位需求吧!

發表於: 2004/7/7 13:40
頂部


Re: 新手請問
版主
版主


記住一個原則:
5V 會振盪不代表振盪電路就沒問題,最好用電源供應器從 3V 到 5.5V的範圍用10M ohm 輸入組抗的示波器量一下振福是否都大於 0.8Vp-p(OSC2腳), 這樣就比較不會發生Crystal與PIC匹配不良,進而產生不起振的現象。

發表於: 2004/7/7 11:52
頂部


Re: 關於LIN BUS的問題?
版主
版主


LIN Bus 一般都使用低價位的RC振盪器,Master與Slave之間可能有15%的頻率誤差,所以Slave端就需要有 Auto Baud-Rate 的功能
首先我們先看看 LIN Bus 的 Protocal (參考AN729說明
http://ww1.microchip.com/downloads/en/AppNotes/00729a.pdf )

13-bit Sync Break(Low) + 0x55 (Sync Field) + ID (2-bit Party + 6-bit ID) + DATA (1~8 bytes) + Checksum
Sync Break 是用來通知所有的Slave, Master 即將送出資料
Sunc Field 是 0x55,也就是會有1,0,1,0,1,0,1,0 的clock送出,Slave用此訊號計算傳輸速率。
ID以後的格式請看AN729的說明。

-- 在Microchip的元件中只有EUSART有Sync Break及Auto Baud Rate Detected的功能,就可以直接使用於LIN protocol(此範例可參考AN864)
-- 如果使用一般USART(例16F877)也可以用Timer做為Baud Rate的計算配合USART也可以使用於LIN protocol(此範例可參考AN237)
-- 如果你是使用最便宜的MCU(16C433,16C57...)這些元件都不含UART的介面,這時候你就用I/O及軟體方式計算Baud Rate及用Software UART的功能模擬接收與傳送功能,還好LIB Bus的最高速度不超過20Kbps,用PIC來做也很簡單(此範例可參考AN240)

相關的Application Note 請參考 http://www.microchip.com/stellent/idc ... &nodeId=1490&filterID=400

不過我看了樓上的各位大大,那麼晚了怎麼還不睡啊!

發表於: 2004/7/7 10:58
頂部


Re: 用C寫的書要出版了?
版主
版主


宏友圖書開發及將發行 "PIC18Fxx2 為控制器原理與實作 -- 使用組合語言及C語言" 聯絡電話 02-23699785

發表於: 2004/7/2 16:40
頂部



« 1 ... 1602 1603 1604 (1605) 1606 1607 1608 ... 1610 »



:::

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... ]

教育訓練中心

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