Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

bits, bytes & Registers - Solved - Thank you

Status
Not open for further replies.

SwingeyP

Member
After configuring the simulator properly and realising that I was trying to drive the 2 displays from one port I managed to get my head around shiftleft and shiftright.

All working now - I hope.

Code:
Dim digit As Byte  'input variable for GETMASK subroutine
Dim digit1 As Byte  'current high digit
Dim digit2 As Byte  'current low digit
Dim mask As Byte  'output variable from GETMASK subroutine
Dim mask1 As Byte  'current high digit mask
Dim mask2 As Byte  'current low digit mask
Dim i As Byte


Symbol d1enable = PORTA.0  'enable line for higher 7-segment display
Symbol d2enable = PORTA.1  'enable line for lower 7-segment display

TRISA.0 = 0  'set RC0 pin as output
TRISA.1 = 0  'set RC1 pin as output
TRISB = %00000000  'set PORTB pins as outputs Display 1
TRISC = %00000000  'set PORTc pins as outputs Display 2
TRISD = %11111111  'Set port D to input

d1enable = True
d2enable = True
mask1 = 0
mask2 = 0

loop:
For i = 0 To 255
	digit1 = ShiftLeft(PORTD, 4)  'Get the lower 4 bits
	digit1 = digit1 / 16
	digit2 = ShiftRight(PORTD, 4)  'Get the upper 4 bits
		
	digit = digit1
	Gosub getmask  'get mask for high digit
	mask1 = mask
	
	digit = digit2
	Gosub getmask  'get mask for low digit
	mask2 = mask
	
	Gosub show  'display new mask
		
	'delay interval suitable for simulation
'use large delay for the real device, say WAITMS 500
Next i
Goto loop
End                                               

getmask:  'get appropriate 7-segment mask for input digit
mask = LookUp(0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71), digit
Return                                            


show:
PORTB = mask1
PORTC = mask2
Return
Infact looking at it I don't need the for next loop anymore.

Thanks for the help.

Regards - Paul
 
Thanks very much. I never really understtod properly how shiftleft / shift right worked in terms of being able to use it. I can clearly see now that left multiples by 2 each time and right rivids by 2 each time. This has opened a whole new world of bit manipulation. How did I ever manage without it .... lol :D

Thanks very much.

This whole thing is really to develop some tones depending on what is seen on 6 address lines. This bit was to discover what was present on the six address lines. Now I have that info I have started on the tone bit.

Regards - Paul
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top