Outpins variable affecting portC

Panda1989

Member
Hi.

Whenever I use "outpins = %00000000", my PortC pins are also switched off, even though technically portC pins are defined as inputs. Anybody know why this is? This is a project-crippling problem I have right here!

Sample code:

Code:
high portc 0 ' PortC 0 switched on
outpins = %00000000 ' PortC 0 switched off?!
Thanks.
 
Last edited:

BCJKiwi

Senior Member
Page 17 of Manual2 suggests;

let outpinsB = %11000011

So it looks like you need to specify the port on the 28/40X1
 

eclectic

Moderator
Panda.
Could you post your circuit diagram and any other relevant information please.

I've just tried your two line program, using an AXE022 board.

I attached an LED/resistor to c0.

First, I ran the simulator, then a real 28X, then real 40X.

In all cases, the LED stayed ON.

e.
 

Panda1989

Member
Panda.
Could you post your circuit diagram and any other relevant information please.

I've just tried your two line program, using an AXE022 board.

I attached an LED/resistor to c0.

First, I ran the simulator, then a real 28X, then real 40X.

In all cases, the LED stayed ON.

e.
I agree, when I run just that example code the LED does stay on. Sorry for the confusion. Maybe it's just my code. Here it is:

Code:
  Symbol ADVal = W0
  Symbol TC_100 = W0	' ADVal not needed when TC_100 is calculated

  Symbol ADValHi8 = B2
  Symbol ADValLow2 = B3
  Symbol N = B4
  Symbol Diff = B5
  Symbol Whole = B6
  Symbol Fract = B7
  Symbol SignFlag = B4	' N is not need when this is used
  Symbol Diga = B5	' Diff not needed when this is used

  symbol loop_dump = w8
  symbol math_dump = w9
  symbol math_dump2 = w10
  symbol temp = w11

  symbol digit_1 = b12
  symbol digit_2 = b13
  symbol digit_1_buffer = b14
  symbol digit_2_buffer = b15


'''''''''''''''''''''''''''''''''''''''''''''''''''''''
 ' EEPROM locations 0 - 15 not used

  EEPROM 16, (254, 236, 220, 206, 194, 183, 173, 164)
  EEPROM 24, (157, 149, 143, 137, 131, 126, 122, 117)
  EEPROM 32, (113, 110, 106, 103, 100, 97, 94, 92)
  EEPROM 40, (89, 87, 85, 83, 81, 79, 77, 76)
  EEPROM 48, (74, 73, 71, 70, 69, 67, 66, 65)
  EEPROM 56, (64, 63, 62, 61, 60, 59, 58, 57)
  EEPROM 64, (57, 56, 55, 54, 54, 53, 52, 52)
  EEPROM 72, (51, 51, 50, 49, 49, 48, 48, 47)
  EEPROM 80, (47, 46, 46, 46, 45, 45, 44, 44)
  EEPROM 88, (44, 43, 43, 43, 42, 42, 42, 41)
  EEPROM 96, (41, 41, 41, 40, 40, 40, 40, 39)
  EEPROM 104, (39, 39, 39, 39, 38, 38, 38, 38)
  EEPROM 112, (38, 38, 37, 37, 37, 37, 37, 37)
  EEPROM 120, (37, 36, 36, 36, 36, 36, 36, 36)
  EEPROM 128, (36, 36, 36, 36, 36, 35, 35, 35)
  EEPROM 136, (35, 35, 35, 35, 35, 35, 35, 35)
  EEPROM 144, (35, 35, 35, 35, 35, 35, 35, 35)
  EEPROM 152, (35, 35, 35, 35, 35, 35, 35, 35)
  EEPROM 160, (36, 36, 36, 36, 36, 36, 36, 36)
  EEPROM 168, (36, 36, 36, 37, 37, 37, 37, 37)
  EEPROM 176, (37, 37, 38, 38, 38, 38, 38, 39)
  EEPROM 184, (39, 39, 39, 39, 40, 40, 40, 41)
  EEPROM 192, (41, 41, 42, 42, 42, 43, 43, 43)
  EEPROM 200, (44, 44, 45, 45, 46, 46, 47, 47)
  EEPROM 208, (48, 48, 49, 50, 50, 51, 52, 53)
  EEPROM 216, (53, 54, 55, 56, 57, 58, 59, 61)
  EEPROM 224, (62, 63, 65, 66, 68, 70, 72, 74)
  EEPROM 232, (76, 78, 81, 84, 87, 90, 94, 98)
  EEPROM 240, (102, 107, 113, 119, 126, 135, 144, 156)
  EEPROM 248, (170, 187, 208, 235)
  
  put 0, %01111110
  put 1, %00001100
  put 2, %10110110
  put 3, %10011110
  put 4, %11001100
  put 5, %11011010
  put 6, %11111010
  put 7, %00001110
  put 8, %11111110
  put 9, %11011110 
  
  low portc 3
  
Top:
  GoSub MeasTemp
  If TC_100 = $7fff Then OutofRange
  GoSub DisplayTemp

OutofRange:
  SerTxD ("Out of Range", 10, 13)
  GoTo Top

MeasTemp:

  ReadADC10 0, ADVal
  pause 100
  ADValHi8 = ADVal / 4    ' isolate the high 8 bits
  ADValLow2 = ADVal & $03 ' low two bits

  TC_100 = 10542 ' adjust this as required
  If ADValHi8 < 16 Then TooHot
  If ADValHi8 > 251 Then TooCold


  For N = 0 to ADValHi8 ' continue to subtract
     Read N, Diff
     TC_100 = TC_100 - Diff
  Next
  ' Now for the low two bits, a linear interpolation

  N = N + 1
  Read N, Diff
  Diff = Diff / 4 * ADValLow2

  TC_100 = TC_100 - Diff

MeasTemp_1:

  Return

TooHot:
TooCold:
   TC_100 = $7fff
   GoTo MeasTemp_1


DisplayTemp:
  SignFlag = Tc_100 / 256 / 128
  If SignFlag = 0 Then Positive
    TC_100 = TC_100 ^ $ffff + 1	' twos comp
    SerTxD ("-")

Positive:

  Whole = TC_100 / 100
  Fract = TC_100 % 100
  SerTxD (#Whole, ".")
  ' be sure the fractional is two digits
  Diga = Fract / 10
  SerTxD (#Diga)
  Diga = Fract % 10
  SerTxD (#Diga, 10, 13)
  
  ' Check for Fan
  if Whole>=20 then
    high portc 3
  elseif Whole<20 then
    low portc 3
  endif
  
  'Check for Alarm
  if Whole>60 then
    high portc 4
    high portc 5
  elseif Whole<=60 then
    low portc 4
    low portc 5
  endif
  
  temp = Whole
  SerTxd( "Temperature: ", #temp, CR, LF )
   
  ' Calculate First Digit
		if temp < 100 then
			do
				let math_dump = loop_dump+10
				
				if temp >= loop_dump AND temp < math_dump then
					let digit_1 = loop_dump/10
					exit
				endif
				
				let loop_dump = loop_dump+10
						
			loop while loop_dump <= 100
			
			let loop_dump=0
			let math_dump=0
		else
			let digit_1 = 10
			
			let loop_dump=0
			let math_dump=0
		endif
	
	
		' Calculate Second Digit
		if digit_1 != 10 then
			let math_dump2 = digit_1*10
			let math_dump2 = temp - math_dump2
			
			do
				let math_dump = loop_dump+1
				
				
				if math_dump2 = loop_dump then
					let digit_2 = loop_dump
					exit
				endif
				
				let loop_dump = loop_dump+1
						
			loop while loop_dump <= 9
			
			let loop_dump=0
			let math_dump=0
		else
			let digit_1 = 9
			let digit_2 = 9
			
			let loop_dump=0
			let math_dump=0
		endif
		
		' Digit 1 Buffer
		get digit_1, digit_1_buffer
			
		' Digit 2 Buffer
		get digit_2, digit_2_buffer
		
		
		' Display each digit 500 times (takes 1 sec approx)
		do
			' Display First Digit
			
			high portc 2  ' Digit 1 On
			low portc 1   ' Digit 2 Off
			outpins = digit_1_buffer
			pause 1
			
			outpins = %00000000			
		
			low portc 2  ' Digit 1 Off
			high portc 1   ' Digit 2 On
			outpins = digit_2_buffer
			pause 1
			
			outpins = %00000000			
			
			loop_dump = loop_dump+1
		
		loop while loop_dump < 500
	
		let loop_dump = 0
		let math_dump = 0 
  Goto Top

OK, so I've found out that this only affects portC 4 and 5 in my code (under 'Check for Alarm'). PortC 4 and 5 with briefly turn high, then will turn off again. Strangely enough this does not affect portC 3. I HAVE tested portC pins 3-5 with my example code and this problem does not occur, so this makes the outpins variable less likely to be responsible, but seemed the only logical explanation at the time of thread creation.
 
Last edited:

Technical

Technical Support
Staff member
Have you tried adding a 'let dirsc = ' line at the start of the program to correctly setup the portc inputs/output arrangement?
 

hippy

Ex-Staff (retired)
Have you tried running you code through the simulator ?

Other than that it's probably a case of adding SERTXD commands to sipsplay current state, change to be applied and output state until you find an anomoly, then it's back-tracking to discover why.

The commonest mistake I make with pins= or outpins= is that a pin high doesn't have the bit set in what's being assigned so it will be cleared.
 
Top