Definning a VAR for Different Register Bits


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637

    Default Definning a VAR for Different Register Bits

    Hi all,

    I'm playing with a multiplexed LCD display that has 4 commons. The PIC that I'm using is the 16F1939. This PIC has a bunch of registers to set the segments in the LCD either on or off. Here are some of the registers,

    • LCDDATA0 SEG<7:0>COM0
    • LCDDATA1 SEG<15:8>COM0
    • LCDDATA2 SEG<23:16>COM0(1)
    • LCDDATA3 SEG<7:0>COM1
    • LCDDATA4 SEG<15:8>COM1
    • LCDDATA5 SEG<23:16>COM1(1)
    • LCDDATA6 SEG<7:0>COM2
    • LCDDATA7 SEG<15:8>COM2
    • LCDDATA8 SEG<23:16>COM2(1)
    • LCDDATA9 SEG<7:0>COM3
    • LCDDATA10 SEG<15:8>COM3
    • LCDDATA11 SEG<23:16>COM3(1)
    What I'm trying to do is to define a variable that contains different bits from different registers. For example, I want to define the following variable

    Code:
    DIGIT1.0 = LCDDATA0.0
    DIGIT1.1 = LCDDATA3.0
    DIGIT1.2 = LCDDATA6.0
    DIGIT1.3 = LCDDATA9.0
    DIGIT1.4 = LCDDATA0.1
    DIGIT1.5 = LCDDATA3.1
    DIGIT1.6 = LCDDATA6.1
    DIGIT1.7 = LCDDATA9.1
    Can this be done using VAR or SYMBOL? Any ideas / comments?

    Thank you,

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: Definning a VAR for Different Register Bits

    Hi,
    No, it doesn't work that way.
    If you want the content of one variable (byte, word or long) to be "split up" and "spread" across several other variables or register you basically have to do it manually, exactly the way you show it.

    /Henrik.

  3. #3
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: Definning a VAR for Different Register Bits

    Hmm, I was hopping it could be done using VAR or SYMBOL, since I don't have much free programming space in my chip.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Definning a VAR for Different Register Bits

    Here is a 4 digit counting demo using the pic16f913. Hope it helps

    Code:
    'PIC16F914  4 Digit LCD Counter Demo
    'Purpose to Drive non-inteligent LCD displays with on chip LCD module
    'Vishay VM404 LCD 4 digit, 7 segment  -mouser elect
    'LCD BIAS RESISTER LADDER 3x 47k VCC-VDD
    ' July 2006 Mark S
    '***********************************************************************
    
    DEFINE 	OSC		4		        ' Set Xtal Frequency
    
    CMCON0 =%00000111   'COMPARATOR OFF
    ADCON0 =%00000000   'ADC off
    
    'SET LCD REGISTERS
    LCDCON = %10010010 'LCD ENABLED,SLEEP-LCD ON,ERR OFF,BIAS ON,CLK F/8192,MUX 1/3
    
    LCDPS  = %00110000 ' SEE DATA SHEET
    
    LCDSE0  =%11111111  'SEGMENTS 0-7 ON
    LCDSE1  =%00001111  'SEGMENTS 8-11 ON 12-15 OFF
    LCDSE2  =%00000000 	'SEGMENTS 16 - 23 OFF
    
    'VARIABLES
    adval   VAR WORD
    XCOUNT  VAR WORD
    TEMPX   VAR WORD
    ONES    VAR byte
    TENS    VAR byte
    HUNS    VAR byte
    THOU    VAR byte  		
    DIG1	VAR	BYTE
    DIG2	VAR BYTE
    DIG3	VAR	BYTE
    DIG4	VAR BYTE
    DP1		VAR	BIT
    DP2		VAR BIT
    DP3		VAR BIT  
    
    
    TRISA = %00000000		
    TRISB= %00000000
    TRISC= %00000000
    TRISD= %00000000
    TRISE= %00000000  
    
    'Clear LCD     
         XCOUNT = 0
      
         LCDDATA0 = 0 : LCDDATA1=0 : LCDDATA2=0 : LCDDATA3=0
         LCDDATA4 = 0 : LCDDATA5=0 : LCDDATA6=0 : LCDDATA7=0
         LCDDATA8 = 0 : LCDDATA9=0 : LCDDATA10=0 : LCDDATA11=0 
         
    '====================================================================== 	
    'MAIN
    '-----------------------------------------------------------------------
     START:
    'Count loop 0 to 9999          
     TEMPX = TEMPX + 1
        XCOUNT = TEMPX
        THOU = XCOUNT/1000 
        XCOUNT = XCOUNT//1000
        HUNS = XCOUNT/100
        XCOUNT = Xcount//100
        TENS = XCOUNT/10
        ones = XCOUNT//10
        
    '====================================================================== 
    LCD OUT:
    
    
        'SEVEN SEG LOOKUP
        LookUp ONES,[63,6,91,79,102,109,124,7,127,103,0],DIG4
        LookUp TENS,[63,6,91,79,102,109,124,7,127,103,0],DIG3
        LookUp HUNS,[63,6,91,79,102,109,124,7,127,103,0],DIG2
        LookUp THOU,[63,6,91,79,102,109,124,7,127,103,0],DIG1
    
         LCDDATA6.0 = 1    'Decimal Point
        'LOAD LCD REGISTERS
          
          LCDDATA0.4 = DIG4.0	'D4A	=	LCDDATA0.4	
          LCDDATA0.3 = DIG4.1    	'D4B	=	LCDDATA0.3
          LCDDATA3.3 = DIG4.2    	'D4C	=	LCDDATA3.3
          LCDDATA6.4 = DIG4.3   	'D4D	=	LCDDATA6.4
          LCDDATA3.5 = DIG4.4   	'D4E	=	LCDDATA3.5
          LCDDATA0.5 = DIG4.5  	'D4F	=	LCDDATA0.5
          LCDDATA3.4 = DIG4.6   	'D4G	=	LCDDATA3.4
        
          LCDDATA0.6 = DIG3.0   	'D3A	=	LCDDATA0.6
          LCDDATA0.2 = DIG3.1   	'D3B	=	LCDDATA0.2
          LCDDATA3.2 = DIG3.2  	'D3C	=	LCDDATA3.2
          LCDDATA6.6 = DIG3.3   	'D3D	=	LCDDATA6.6
          LCDDATA3.7 = DIG3.4   	'D3E	=	LCDDATA3.7
          LCDDATA0.7 = DIG3.5   	'D3F	=	LCDDATA0.7
          LCDDATA3.6 = DIG3.6   	'D3G	=	LCDDATA3.6
         
          LCDDATA1.0 = DIG2.0   	'D2A	=	LCDDATA1.0
          LCDDATA0.1 = DIG2.1   	'D2B	=	LCDDATA0.1
          LCDDATA3.1 = DIG2.2   	'D2C	=	LCDDATA3.1
          LCDDATA7.0 = DIG2.3   	'D2D	=	LCDDATA7.0	
          LCDDATA4.1 = DIG2.4   	'D2E	=	LCDDATA4.1
          LCDDATA1.1 = DIG2.5   	'D2F	=	LCDDATA1.1
          LCDDATA4.0 = DIG2.6   	'D2G	=  	LCDDATA4.0
         
          LCDDATA1.2 = DIG1.0   	'D1A	=	LCDDATA1.2
          LCDDATA0.0 = DIG1.1   	'D1B	=	LCDDATA0.0
          LCDDATA3.0 = DIG1.2   	'D1C	=	LCDDATA3.0
          LCDDATA7.2 = DIG1.3   	'D1D	=	LCDDATA7.2
          LCDDATA4.3 = DIG1.4   	'D1E	=	LCDDATA4.3
          LCDDATA1.3 = DIG1.5   	'D1F	=	LCDDATA1.3
          LCDDATA4.2 = DIG1.6    	'D1G	=	LCDDATA4.2
         PAUSE 200
    
    
            'CLEAR LCD REGISTERS
         
         LCDDATA0 = 0 : LCDDATA1=0 : LCDDATA2=0 : LCDDATA3=0
         LCDDATA4 = 0 : LCDDATA5=0 : LCDDATA6=0 : LCDDATA7=0
         LCDDATA8 = 0 : LCDDATA9=0 : LCDDATA10=0 : LCDDATA11=0  
         LCDDATA6.0 = 0 'DP    
         
        IF XCOUNT = 9999 THEN ZERO_X 
        
        GOTO START
        ZERO_X: XCOUNT = 0    'Reset counter
        GOTO START  
         
        
    End

  5. #5
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: Definning a VAR for Different Register Bits

    Thank you guys. That code gives me some ideas for my own program.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

Similar Threads

  1. Replies: 2
    Last Post: - 23rd April 2013, 17:34
  2. 7.6.5 Applying Offsets to Bits within a Variable or Register
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 30th November 2011, 08:27
  3. DT_INTS-14 /interrupts enable bits / flag bits
    By bogdan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 16th May 2009, 19:42
  4. assigning register bits to an array?
    By bakerajatha in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 19th January 2009, 20:12
  5. calculate var Byte's and var Word's
    By Pedro Pinto in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st October 2005, 10:29

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts