Please help with the assembly code

Reply

Join Date: Oct 2005
Posts: 11
Reputation: perpetual_dream is an unknown quantity at this point 
Solved Threads: 0
perpetual_dream perpetual_dream is offline Offline
Newbie Poster

Please help with the assembly code

 
0
  #1
Jun 2nd, 2006
Hey,
I am willing to use the following code in one phase of my project. The problem is that i dont understand this assembly language, In school I took it in different form...
Mov ax, bx
out 11, AL bla bla...
here the registers is different and everything is different....
All I need is to know what are the input and output pins...
say port A0-A3 INPUT
PORT B0-B7 OUTPUT
bc i really dont know the input and output ports in the code...
the code is to be used on pic16f628 here is the microcontroller datasheet in case u need it
http://ww1.microchip.com/downloads/e...Doc/40300C.pdf
and here is the code:

  1. ;Tutorial 7_5
  2. ;Serial routines - display received bytes on LED's
  3. ;Nigel Goodwin 2003
  4.  
  5. LIST p=16F628 ;tell assembler what chip we are using
  6. include "P16F628.inc" ;include the defaults for the chip
  7. ERRORLEVEL 0, -302 ;suppress bank selection messages
  8. ;sets the configuration settings (oscillator type etc.)
  9.  
  10.  
  11.  
  12.  
  13. cblock 0x20 ;start of general purpose registers
  14. count ;used in looping routines
  15. count1 ;used in delay routine
  16. counta ;used in delay routine
  17. countb ;used in delay routine
  18. Xmit_Byte ;holds byte to xmit
  19. Rcv_Byte ;holds received byte
  20. Bit_Cntr ;bit counter for RS232
  21. Delay_Count ;delay loop counter
  22. endc
  23.  
  24. SER_PORT Equ PORTA
  25. SER_TRIS Equ TRISA
  26. SER_IN Equ 0x07
  27. SER_OUT Equ 0x06
  28. LED_PORT Equ PORTB
  29. LED_TRIS Equ TRISB
  30.  
  31. org 0x0000
  32.  
  33. Start movlw 0x07
  34. movwf CMCON ;turn comparators off (make it like a 16F84)
  35.  
  36. Initialise clrf count
  37. clrf PORTA
  38. clrf PORTB
  39. BSF STATUS, RP0 ;select bank 1
  40. clrf LED_TRIS ;make LED_Port all outputs
  41. BCF STATUS, RP0 ;select bank 0
  42. call SER_INIT ;initialise serial port
  43. Loop call Rcv_RS232
  44. movwf LED_PORT ;transfer byte to LED's
  45. call XMIT_RS232 ;echo character back
  46. goto Loop
  47.  
  48.  
  49. ;Serial routines
  50.  
  51. SER_INIT
  52. BSF STATUS, RP0 ;select bank 1
  53. BCF SER_TRIS, SER_OUT ;set B6 as an output
  54. BSF SER_TRIS, SER_IN ;set B7 as an input
  55. BCF STATUS, RP0 ;select bank 0
  56. BSF SER_PORT, SER_OUT ;set SER_OUT high
  57. RETURN
  58.  
  59. XMIT_RS232 MOVWF Xmit_Byte ;move W to Xmit_Byte
  60. MOVLW 0x08 ;set 8 bits out
  61. MOVWF Bit_Cntr
  62. BCF SER_PORT, SER_OUT
  63. CALL Bit_Delay
  64. Ser_Loop RRF Xmit_Byte , f ;send one bit
  65. BTFSS STATUS , C
  66. BCF SER_PORT, SER_OUT
  67. BTFSC STATUS , C
  68. BSF SER_PORT, SER_OUT
  69. CALL Bit_Delay
  70. DECFSZ Bit_Cntr , f ;test if all done
  71. GOTO Ser_Loop
  72. BSF SER_PORT, SER_OUT
  73. CALL Bit_Delay
  74. RETURN
  75.  
  76. Rcv_RS232 BTFSC SER_PORT, SER_IN ;wait for start bit
  77. GOTO Rcv_RS232
  78. CALL Start_Delay ;do half bit time delay
  79. BTFSC SER_PORT, SER_IN ;check still in start bit
  80. GOTO Rcv_RS232
  81. MOVLW 0x08 ;set up to read 8 bits
  82. MOVWF Bit_Cntr
  83. CLRF Rcv_Byte
  84. Next_RcvBit CALL Bit_Delay
  85. BTFSS SER_PORT, SER_IN
  86. BCF STATUS , C
  87. BTFSC SER_PORT, SER_IN
  88. BSF STATUS , C
  89. RRF Rcv_Byte , f
  90. DECFSZ Bit_Cntr , f ;test if all done
  91. GOTO Next_RcvBit
  92. CALL Bit_Delay
  93. MOVF Rcv_Byte, W
  94. RETURN
  95.  
  96. Start_Delay MOVLW 0x0C
  97. MOVWF Delay_Count
  98. Start_Wait NOP
  99. DECFSZ Delay_Count , f
  100. GOTO Start_Wait
  101. RETURN
  102.  
  103. Bit_Delay MOVLW 0x18
  104. MOVWF Delay_Count
  105. Bit_Wait NOP
  106. DECFSZ Delay_Count , f
  107. GOTO Bit_Wait
  108. RETURN
  109.  
  110.  
  111. ;Delay routines
  112.  
  113. Long_Delay
  114. call Delay255
  115. call Delay255
  116. call Delay255
  117. call Delay255
  118. return
  119.  
  120. Delay255 movlw 0xff ;delay 255 mS
  121. goto d0
  122. Delay100 movlw d'100' ;delay 100mS
  123. goto d0
  124. Delay50 movlw d'50' ;delay 50mS
  125. goto d0
  126. Delay20 movlw d'20' ;delay 20mS
  127. goto d0
  128. Delay10 movlw d'10' ;delay 10mS
  129. goto d0
  130. Delay1 movlw d'1' ;delay 1mS
  131. goto d0
  132. Delay5 movlw 0x05 ;delay 5.000 ms (4 MHz clock)
  133. d0 movwf count1
  134. d1 movlw 0xC7
  135. movwf counta
  136. movlw 0x01
  137. movwf countb
  138. Delay_0 decfsz counta, f
  139. goto $+2
  140. decfsz countb, f
  141. goto Delay_0
  142.  
  143. decfsz count1 ,f
  144. goto d1
  145. retlw 0x00
  146.  
  147. ;end of Delay routines
  148.  
  149.  
  150. end

thnx a lot in advance
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 233
Reputation: Lord Soth is an unknown quantity at this point 
Solved Threads: 4
Lord Soth's Avatar
Lord Soth Lord Soth is offline Offline
Posting Whiz in Training

Re: Please help with the assembly code

 
1
  #2
Aug 9th, 2006
Hi,

I suggest you to download the main PIC 16F84A manual. (or the one related to your PIC) There you will see a list of registers and opcodes. Actually for PIC registers is like memory (there are a lot of theme) and the only register is working register which is W. For example you can't move a value to a register directly you have to load it to working register first : movlw .01010101; movwf TRISA
The TRIS_ registers adjust wether the pins of the related port (TRISA -> PORTA) are to be used for input or output. (not both are possible for all port/pins) There also are two memory (register) banks you have to set

BSF STATUS, RP0 ; bit set status register bit RP0 to select bank 1
clrf TRISA ;make PORTA all pins outputs
BCF STATUS, RP0 ;select back bank 0

PORTA,PORTB,... are on bank 0 and TRISA, TRISB, ... are on bank 1 (check register map on the reference)

clrf PORTA; clear all bits/pins of PORTA

Those are the basics, post if you need any more knowledge.

Loren Soth
Best regards,
Loren Soth

Crimson K. Software _________________________________________________________________ Crimson K. Blog
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC