+ Reply to Thread
Page 1 of 2
1 2 Last
Results 1 to 15 of 17

Thread: Define many constant in Assembly

  1. #1
    Ayne Newbie
    Join Date
    Apr 2006
    Location
    Multan, Pakistan.
    Posts
    416

    Question Define many constant in Assembly

    Code:
    '   6x8 Font Table 
    const font1 as byte[230] = 
    (0x00, 0x00, 0x00, 0x00, 0x00 ,   '   space 
     0x00, 0x00, 0x2f, 0x00, 0x00 ,   '   ! 
     0x00, 0x07, 0x00, 0x07, 0x00 ,   '   " 
     0x14, 0x7f, 0x14, 0x7f, 0x14 ,   '   # 
     0x24, 0x2a, 0x7f, 0x2a, 0x12 ,   '   $ 
     0x62, 0x64, 0x08, 0x13, 0x23 ,   '   % 
     0x36, 0x49, 0x55, 0x22, 0x50 ,   '   & 
     0x00, 0x05, 0x03, 0x00, 0x00 ,   '   ' 
     0x00, 0x1c, 0x22, 0x41, 0x00 ,   '   ( 
     0x00, 0x41, 0x22, 0x1c, 0x00 ,   '   ) 
     0x14, 0x08, 0x3E, 0x08, 0x14 ,   '   * 
     0x08, 0x08, 0x3E, 0x08, 0x08 ,   '   + 
     0x00, 0x00, 0xA0, 0x60, 0x00 ,   '   , 
     0x08, 0x08, 0x08, 0x08, 0x08 ,   '   - 
     0x00, 0x60, 0x60, 0x00, 0x00 ,   '   . 
     0x20, 0x10, 0x08, 0x04, 0x02 ,   '   / 
     0x3E, 0x51, 0x49, 0x45, 0x3E ,   '   0 
     0x00, 0x42, 0x7F, 0x40, 0x00 ,   '   1 
     0x42, 0x61, 0x51, 0x49, 0x46 ,   '   2 
     0x21, 0x41, 0x45, 0x4B, 0x31 ,   '   3 
     0x18, 0x14, 0x12, 0x7F, 0x10 ,   '   4 
     0x27, 0x45, 0x45, 0x45, 0x39 ,   '   5 
     0x3C, 0x4A, 0x49, 0x49, 0x30 ,   '   6 
     0x01, 0x71, 0x09, 0x05, 0x03 ,   '   7 
     0x36, 0x49, 0x49, 0x49, 0x36 ,   '   8 
     0x06, 0x49, 0x49, 0x29, 0x1E ,   '   9 
     0x00, 0x36, 0x36, 0x00, 0x00 ,   '   : 
     0x00, 0x56, 0x36, 0x00, 0x00 , 
     0x08, 0x14, 0x22, 0x41, 0x00 ,   '   < 
     0x14, 0x14, 0x14, 0x14, 0x14 ,   '   = 
     0x00, 0x41, 0x22, 0x14, 0x08 ,   '   > 
     0x02, 0x01, 0x51, 0x09, 0x06 ,   '   ? 
     0x32, 0x49, 0x59, 0x51, 0x3E ,   '   @ 
     0x7C, 0x12, 0x11, 0x12, 0x7C ,   '   A 
     0x7F, 0x49, 0x49, 0x49, 0x36 ,   '   B 
     0x3E, 0x41, 0x41, 0x41, 0x22 ,   '   C 
     0x7F, 0x41, 0x41, 0x22, 0x1C ,   '   D 
     0x7F, 0x49, 0x49, 0x49, 0x41 ,   '   E 
     0x7F, 0x09, 0x09, 0x09, 0x01 ,   '   F 
     0x3E, 0x41, 0x49, 0x49, 0x7A ,   '   G 
     0x7F, 0x08, 0x08, 0x08, 0x7F ,   '   H 
     0x00, 0x41, 0x7F, 0x41, 0x00 ,   '   I 
     0x20, 0x40, 0x41, 0x3F, 0x01 ,   '   J 
     0x7F, 0x08, 0x14, 0x22, 0x41 ,   '   K 
     0x7F, 0x40, 0x40, 0x40, 0x40 ,   '   L 
     0x7F, 0x02, 0x0C, 0x02, 0x7F)    '   M 
      
     const font2 as byte[230] = 
    (0x7F, 0x04, 0x08, 0x10, 0x7F ,   '   N 
     0x3E, 0x41, 0x41, 0x41, 0x3E ,   '   O 
     0x7F, 0x09, 0x09, 0x09, 0x06 ,   '   P 
     0x3E, 0x41, 0x51, 0x21, 0x5E ,   '   Q 
     0x7F, 0x09, 0x19, 0x29, 0x46 ,   '   R 
     0x46, 0x49, 0x49, 0x49, 0x31 ,   '   S 
     0x01, 0x01, 0x7F, 0x01, 0x01 ,   '   T 
     0x3F, 0x40, 0x40, 0x40, 0x3F ,   '   U 
     0x1F, 0x20, 0x40, 0x20, 0x1F ,   '   V 
     0x3F, 0x40, 0x38, 0x40, 0x3F ,   '   W 
     0x63, 0x14, 0x08, 0x14, 0x63 ,   '   X 
     0x07, 0x08, 0x70, 0x08, 0x07 ,   '   Y 
     0x61, 0x51, 0x49, 0x45, 0x43 ,   '   Z 
     0x00, 0x7F, 0x41, 0x41, 0x00 ,   '   [ 
     0x55, 0x2A, 0x55, 0x2A, 0x55 ,   '   / 
     0x00, 0x41, 0x41, 0x7F, 0x00 ,   '   ] 
     0x04, 0x02, 0x01, 0x02, 0x04 ,   '   ^ 
     0x40, 0x40, 0x40, 0x40, 0x40 ,   '   _ 
     0x00, 0x01, 0x02, 0x04, 0x00 ,   '   ' 
     0x20, 0x54, 0x54, 0x54, 0x78 ,   '   a 
     0x7F, 0x48, 0x44, 0x44, 0x38 ,   '   b 
     0x38, 0x44, 0x44, 0x44, 0x20 ,   '   c 
     0x38, 0x44, 0x44, 0x48, 0x7F ,   '   d 
     0x38, 0x54, 0x54, 0x54, 0x18 ,   '   e 
     0x08, 0x7E, 0x09, 0x01, 0x02 ,   '   f 
     0x18, 0xA4, 0xA4, 0xA4, 0x7C ,   '   g 
     0x7F, 0x08, 0x04, 0x04, 0x78 ,   '   h 
     0x00, 0x44, 0x7D, 0x40, 0x00 ,   '   i 
     0x40, 0x80, 0x84, 0x7D, 0x00 ,   '   j 
     0x7F, 0x10, 0x28, 0x44, 0x00 ,   '   k 
     0x00, 0x41, 0x7F, 0x40, 0x00 ,   '   l 
     0x7C, 0x04, 0x18, 0x04, 0x78 ,   '   m 
     0x7C, 0x08, 0x04, 0x04, 0x78 ,   '   n 
     0x38, 0x44, 0x44, 0x44, 0x38 ,   '   o 
     0xFC, 0x24, 0x24, 0x24, 0x18 ,   '   p 
     0x18, 0x24, 0x24, 0x18, 0xFC ,   '   q 
     0x7C, 0x08, 0x04, 0x04, 0x08 ,   '   r 
     0x48, 0x54, 0x54, 0x54, 0x20 ,   '   s 
     0x04, 0x3F, 0x44, 0x40, 0x20 ,   '   t 
     0x3C, 0x40, 0x40, 0x20, 0x7C ,   '   u 
     0x1C, 0x20, 0x40, 0x20, 0x1C ,   '   v 
     0x3C, 0x40, 0x30, 0x40, 0x3C ,   '   w 
     0x44, 0x28, 0x10, 0x28, 0x44 ,   '   x 
     0x1C, 0xA0, 0xA0, 0xA0, 0x7C ,   '   y 
     0x44, 0x64, 0x54, 0x4C, 0x44 ,   '   z 
     0x14, 0x14, 0x14, 0x14, 0x14)    '   horiz lines
    
    How we define many constants in assembly


  2. #2
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,794

    Default

    Using what processor?.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  3. #3
    Ayne Newbie
    Join Date
    Apr 2006
    Location
    Multan, Pakistan.
    Posts
    416

    Default

    Code:
    sub procedure NOK_Write (dim data as byte, dim mode as byte) 
    dim i as short 
             for i = 0 to 7 step 1 
         '   Pull DC high for DATA or low for COMMAND 
         if TestBit(mode,0) = 1 then 
           SetBit(PortC,5) 
         end if 
         if TestBit(mode,0) = 0 then 
           ClearBit(PortC,5) 
         end if
    next i 
    End Sub
    
    How we define a local variable in Macro in assembly. As we define local variable (i as byte) in above code.


    One thing more, if some one already have a prebuilt macro file for Nokia3310 LCD then plz share or any link???

  4. #4
    Ayne Newbie
    Join Date
    Apr 2006
    Location
    Multan, Pakistan.
    Posts
    416

    Default

    Pic16f877a

  5. #5
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,794

    Default

    The only way on a PIC is to use RETLW tables. The MPASM helpfile shows you how to define them as data statements - or you could check my LED matrix tutorial, which defines fonts for display.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  6. #6
    Ayne Newbie
    Join Date
    Apr 2006
    Location
    Multan, Pakistan.
    Posts
    416

    Default

    dt - Define Table (PIC12/16 MCUs)
    Syntax
    [label] dt expr [, expr, ..., expr]
    Description
    dt - Data Table.

    Generates a series of RETLW instructions, one instruction for each expr. Each expr must be an 8-bit value. Each character in a string is stored in its own RETLW instruction.

    Usage
    This directive is used in the following types of code: absolute or relocatable. For information on types of code, see Assembler Operation.

    This directive is used when generating a table of data for the PIC12/16 device family. If you are using a PIC18 device, it is recommended that you use the table read/write (TBLRD/TBLWT) features. See the device data sheet for more information.

    See Also
    data db de dw
    Simple Example
    dt "A Message", 0
    dt FirstValue, SecondValue, EndOfValues
    i found this, i think this can help me.

    But my second post???? < not answered

  7. #7
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,794

    Default

    Quote Originally Posted by Ayne
    i found this, i think this can help me.

    But my second post???? < not answered
    Again, read the helpfile - it explains all about macros.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  8. #8
    Ayne Newbie
    Join Date
    Apr 2006
    Location
    Multan, Pakistan.
    Posts
    416

    Default

    can we countinu our program to next line in assembly(MPLAB). as in the following code
    0x00, 0x2f, 0x00, 0x00 , ' !
    0x00, 0x07, 0x00, 0x07, 0x00 ,

  9. #9
    Ayne Newbie
    Join Date
    Apr 2006
    Location
    Multan, Pakistan.
    Posts
    416

    Question putting into next line

    Code:
    		; PROGRAM CODE
    START
    		MOVLW	B'10101010'
    		MOVWF	PORTB
    		NOP
    		MOVLW	B'01010101'
    		MOVWF	PORTB
    		NOP
    
    		A DT 0x00, 0x00, 0x00, 0x00, 0x00 ,0x00, 0x07, 0x00, 0x07, 0x00 , 0x14, 0x7f, 0x14, 0x7f, 0x14 , 0x24, 0x2a, 0x7f, 0x2a, 0x12 
    
    		End
    
    As we can see there is a long data after "A DT". How can we put this data into two or three line???

  10. #10
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,794

    Default

    Why not just write the table out?, it's hardly any different - here's a section of mine that I advised you to check earlier!. Notice I used binary as it makes it easy to see what's happening. Also please note, the fonts are upside down!.

    Code:
    Table		
    		RETLW	b'00000000'		;SPACE
                	RETLW   b'00000000'
                	RETLW   b'00000000'		
                	RETLW   b'00000000'		
                	RETLW   b'00000000'		
                	RETLW   b'00000000'		
                	RETLW   b'00000000'		
                	RETLW   b'00000000'
    
    		RETLW	b'00000000'		;!
                	RETLW   b'00010000'
                	RETLW   b'00000000'		
                	RETLW   b'00000000'		
                	RETLW   b'00010000'		
                	RETLW   b'00010000'		
                	RETLW   b'00010000'		
                	RETLW   b'00010000'
    
    		RETLW	b'00000000'		;"
                	RETLW   b'00000000'
                	RETLW   b'00000000'		
                	RETLW   b'00000000'		
                	RETLW   b'00000000'		
                	RETLW   b'00101000'		
                	RETLW   b'00101000'		
                	RETLW   b'00101000'
    
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  11. #11
    Ayne Newbie
    Join Date
    Apr 2006
    Location
    Multan, Pakistan.
    Posts
    416

    Default

    yes u r right Nigel Goodwin, and DT command do the same job.
    But it saves the time, there is no need of writing RETLW on each byte if i use DT command.
    And i am learner i want to learn how to put long data into two or three lines??

  12. #12
    Ayne Newbie
    Join Date
    Apr 2006
    Location
    Multan, Pakistan.
    Posts
    416

    Default

    Have u any prebuilt library for nokia 3310 LCD

  13. #13
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,794

    Default

    Quote Originally Posted by Ayne
    But it saves the time, there is no need of writing RETLW on each byte if i use DT command.
    Have you never heard of 'copy and paste'?.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  14. #14
    Ayne Newbie
    Join Date
    Apr 2006
    Location
    Multan, Pakistan.
    Posts
    416

    Default

    Code:
    sub procedure NOK_Write (dim data as byte, dim mode as byte) 
    dim i as short 
         '   Pull DC high for DATA or low for COMMAND 
         if TestBit(mode,0) = 1 then 
           SetBit(PortC,5) 
         end if 
         if TestBit(mode,0) = 0 then 
           ClearBit(PortC,5) 
         end if 
    
         ClearBit(PortC,0)                                    '   CS = low 
    
         '   Clock in 8 bits of data - Highst bit first 
         for i = 7 to 0 step -1 
              ClearBit(PortC,4)                               '   SCLK = low 
              if TestBit(Data,i) = 0 then 
                ClearBit(PortC,6)                             '   SDA = low 
              else 
                SetBit(PortC,6)                               '   SDA = high 
              end if 
              SetBit(PortC,4)                                 '   SCLK = high 
         next i 
        SetBit(PortC,0)                                       '   CS = high 
    end sub
    
    I wrote the above program i assembly, i use dataa instead data cuz data is the reserve word of MPLAB.
    Plz check the code............ it is write or worng???
    Code:
    ;---------------------------------------------------------------------------------------------------
    ;		
    ;
    ;		NOK_Write	Macro
    ;---------------------------------------------------------------------------------------------------
    
    NOK_Write	Macro	dataa, mode
    		local		I
    
    		if mode,0 == .1			;if mode = 1 then pull DC high
    		bsf		DC
    		endif
    
    		if mode,0 == .0			;if mode = 0 for command pull DC low
    		bcf		DC
    		endif
    
    		bcf		CS				;CS(Chip enable) low << because it active on low
    
        ;*************Clock in 8 bits of data - Highst bit first *************
    		I 	equ		7
    
    		bcf			SCLK		;SCLK - Serial Clock Input = low
    		BTFSS		dataa,I
    		bcf			SDA			;SDA  - Serial Data Input = low
    		bsf			SDA			;SDA  - Serial Data Input = high
    		bsf			SCLK		;SCLK - Serial Clock Input = high
    
    		DECFSZ		I, F
    		Goto		$ - 6
    		bsf			CS			;CS   - Chip Enable = high
    		
    		Endm
    
    I am in learning process, plz tell me if there is any thing wrong or how can i improve it.

  15. #15
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,794

    Default

    Why are you trying to write a macro?.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

+ Reply to Thread
Page 1 of 2
1 2 Last

Similar Threads

  1. DS1302 with PIC16f877 program
    By RasCreationKing in forum Micro Controllers
    Replies: 28
    Latest: 3rd May 2007, 12:03 PM
  2. Defining Constants & Variables
    By Electrix in forum Micro Controllers
    Replies: 19
    Latest: 10th February 2006, 10:43 PM
  3. how to understand this code!!!
    By indie in forum Electronic Projects Design/Ideas/Reviews
    Replies: 3
    Latest: 11th September 2004, 07:39 PM
  4. please help me...
    By indie in forum Micro Controllers
    Replies: 1
    Latest: 29th July 2004, 04:16 AM
  5. help me to describe this code
    By indie in forum Micro Controllers
    Replies: 0
    Latest: 18th June 2004, 01:11 PM

Tags for this Thread