Basic stamp code does not works.


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default Basic stamp code does not works.

    Hello. I have the following basic stamp code:

    Code:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    MXCS PIN 0
    MXSO PIN 1
    MXSCLK PIN 2
    degCouple VAR Word
    degCinternal VAR Word
    TCtemp1 VAR Word
    TCtemp0 VAR Word
    faults VAR Nib
    
    
    SCVfault VAR faults.BIT2
    SCGfault VAR faults.BIT1
    OCfault VAR faults.BIT0
    
    DO
      LOW MXCS 'chip select low
        SHIFTIN MXSO, MXSCLK, MSBPRE, [TCtemp1\16,TCtemp0\16] 'shift in the data
      HIGH MXCS 'chip select high
      degCouple = TCtemp1 >> 2 + (-TCtemp1.BIT15 << 14)   ' the last term extends the sign bit
      degCinternal = TCtemp0 >> 4 + (-TCtemp0.BIT15 << 12)
      faults = TCtemp0.NIB0
      degCouple = (TCtemp1 >> 2) / 4
      DEBUG SDEC degCouple, TAB, SDEC degCinternal, TAB, BIN3 faults
      PAUSE 1000
      DEBUG CLS
    
    LOOP
    Since it is not fully compatible, I've modified faults VAR Nib to faults VAR Byte, and also, instead of "DEBUG", I'm using LCDOUT.

    Still does not works, returns 0 instead of temperature. When same hardware connected to BS2, the code works properly. Pinout seems to be correct. What else can be reason?

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: Basic stamp code does not works.

    I'd look at syntax in these statements first:

    MXCS PIN 0
    SCVfault VAR faults.BIT2


    Then I'd check syntax of DO/LOOP in PBP manual.

    Robert

  3. #3
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Basic stamp code does not works.

    What PIC are you trying to use??
    What version of PBP are you compiling with?

    It's good that you posted the original basic stamp code but it would also be helpful if you posted the PIC code, as modified, that you are trying to run.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Basic stamp code does not works.

    When using stamp basic code that contains "modes" with PBP

    You need to add

    Code:
    Include "modedefs.bas"
    Or change this

    Code:
    SHIFTIN MXSO, MXSCLK, MSBPRE, [TCtemp1\16,TCtemp0\16] 'shift in the data
    to

    Code:
    SHIFTIN MXSO, MXSCLK, 0, [TCtemp1\16,TCtemp0\16] 'shift in the data

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Basic stamp code does not works.

    Hello CuriousOne,
    Very difficult to test this code having only 1/2 of the apparatus (for us). Here is what I would do . . . Add, include"BS2Defs.bas" change
    MXCS PIN 0 . . . to MXCS var PORTx. x etc . . . Change faults = TCtemp0.nib0 to faults = TCtemp0.lowbyte & try it, you might think good thoughts of linking US to the original project so we can get where you are.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  6. #6
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Basic stamp code does not works.

    modedefs.bas is included. When I try to include bs2defs.bas, it gives error during compile on line next to it (no matter what is on there).

    here's the complete listing:

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 26.08.2014                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    ADCON1=%00000110 'CONFIGURE PORT A AS DIGITAL
    Include "Modedefs.bas"
    'INCLUDE "BS2DEFS.BAS"
    Define	OSC	4		' Set Xtal Frequency
    
    	Clk     Var	portb.0		' Data is clocked on rising edge of this pin            kviteli
    	Dta  	Var	portb.1		' Bits are shifted out of this pin          stafilosferi
    	Load    Var	portb.2		' Transfers data to LEDs when Pulsed   lurji
        DQD Var portb.4              ' One-wire data pin FOR THERMOMETER
        
        ' ** Declare Constants **
    	Decode_Reg 	Con	9	' Decode register, a 1 turns on BCD decoding for each digit. 
    	Lum_Reg		Con	10	' Intensity register.
    	Scan_Reg	Con	11	' Scan-limit register.
    	Switch_Reg	Con	12	' On/Off Register.
    	Test_Reg	Con	15	' Test mode register (all digits on, 100% bright)
    
    '	Max_Digit	Con	5	' Amount of LED Displays being used.
    
    ' ** Declare Variables **
      	Counter		Var	Word	' Variable used for the Demo Counting routine
    	Max_Disp	Var	Word	' 16-bit value to be displayed by the MAX7219
    	Max_Dp		Var	Byte	' Digit number to place Decimal point (0-4)
    	Register	Var	Byte	' Pointer to the Internal Registers of the MAX7219
    	R_Val		Var	Byte	' Data placed in Each Register
    	Digit		Var	Byte	' Position of individual numbers within MAX_Disp (0-3)
    	Position	Var	Byte	' Position of each LED display (1-4)
    
    temperature  Var Word       ' Temperature storage
    pause 50
    
     'Alias pins - MAX31855 temp sensor
     MXSCLK var PORTC.1 'MAX31855 Clock 
     MXCS var PORTC.2 'MAX31855 Chip Select 
     MXSO Var PORTC.3 'MAX31855 Serial Data 
    
    
    degCouple VAR Word
    degCinternal VAR Word
    TCtemp1 VAR Word
    TCtemp0 VAR Word
    faults VAR BYTE
    
    SCVfault VAR faults.BIT2
    SCGfault VAR faults.BIT1
    OCfault VAR faults.BIT0
    
    	Register=Scan_Reg		' Point to the Scan Register
    	R_Val=3				' send 3, (Four LED Displays 0-3)
    	Gosub Transfer			' Transfer this 16-bit Word to the MAX7219
    
    	Register=Lum_Reg		' Point to the Luminance Register
    	R_Val=1				' Send 5, (Value for Brightness)
    	Gosub Transfer			' Transfer this 16-bit Word to the MAX7219
    
    	Register=Decode_Reg		' Point to BCD Decode Register
    	R_Val=%00001111			' Decode the first 5 digits
    	Gosub Transfer			' Transfer this 16-bit Word to the MAX7219
    
    	Register=Switch_Reg		' Point to the Switch Register 
    	R_Val=1				' Set to One, (switches the display ON)
    	Gosub Transfer			' Transfer this 16-bit Word to the MAX7219
    
    	Register=Test_Reg		' Point to the Test Register
    	R_Val=0				' Reset to Zero, (turns off Test mode)
    	Gosub Transfer			' Transfer this 16-bit Word to the MAX7219
    
    
    	Max_Dp=1			' Display number for Decimal Point
    	
    	pause 50
    	
    MAX_DISP=4321
    GOSUB DISPLAY
    PAUSE 500	
    do
    GOSUB GRADUS
    max_disp=Tctemp1
    GOSUB DISPLAY
    PAUSE 20
    LOOP
    END	
    	
    	
    Display:
    	Digit=0						' Start at Digit 0 of Max_Disp Variable
    	For Position=4 to 1 step -1			' Start at Farthest Right of Display 		
    	Register=Position				' Place Position into Register
    	R_Val=Max_Disp Dig Digit			' Extract the individual numbers from Max_Disp			
    	If Max_Disp<10 and Position=3 then R_Val=15	' Zero Suppression for the second digit
    	If Max_Disp<100 and Position=2 then R_Val=15	' Zero Suppression for the Third digit
    	If Max_Disp<1000 and Position=1 then R_Val=15	' Zero Suppression for the Forth digit
    	If Max_Disp<10000 and Position=0 then R_Val=15	' Zero Suppression for the Fifth digit
    	If Digit=Max_Dp then R_Val.7=1			' Place the decimal point, held in Max_DP
    	'lcdout $fe,$c0,"Reg:", #register, " VAL:",#R_Val, "   "
    	pause 20
    	Gosub Transfer					' Transfer the 16-bit Word to the MAX7219
    	If Digit>=3 then Digit=0			' We only need the first four digits
    	Digit=Digit+1					' Point to next Digit within Max_Disp
    	Next Position					' Close the Loop
    	Return						' Exit from subroutine
    
    ' Send a 16-bit word to the MAX7219 
    Transfer:
      	Shiftout Dta,Clk,msbfirst,[Register,R_Val] ' Shift Out the Register first, then the data
      	pauseus 100
    	High Load				' The data is now acted upon
    	pauseus 100
    @	Nop
    @	Nop					' A small delay to ensure correct clocking times
    	Low Load				' Disable the MAX7219 
    	Return					' Exit from Subroutine
    	
    	
    GRADUS:
      LOW MXCS 'chip select low
        SHIFTIN MXSO, MXSCLK, MSBPRE, [TCtemp1\16,TCtemp0\16] 'shift in the data
      HIGH MXCS 'chip select high
      degCouple = TCtemp1 >> 2 + (-TCtemp1.BIT15 << 14)   ' the last term extends the sign bit
      degCinternal = TCtemp0 >> 4 + (-TCtemp0.BIT15 << 12)
      'faults = TCtemp0.NIB0
      'degCouple = (TCtemp1 >> 2) / 4
      'DEBUG SDEC degCouple, TAB, SDEC degCinternal, TAB, BIN3 faults
      PAUSE 1000
      'DEBUG CLS
    
      
    return

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: Basic stamp code does not works.

    not sure what ver pbp u have but
    BS1DEFS.BAS and BS2DEFS.BAS
    already includes MODEDEFS.BAS. Do not include it again if one of these files is
    already included. The Mode numbers may be used without including this file. Some
    Modes do not have a name.
    from the pbp3 manual

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Basic stamp code does not works.

    Quote Originally Posted by CuriousOne View Post
    modedefs.bas is included. When I try to include bs2defs.bas, it gives error during compile on line next to it (no matter what is on there).
    As per the manual, use either but not both, bs2defs IS for stamp code use.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  9. #9
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Basic stamp code does not works.

    Yes, as you can see, I had one of them commented, so was enabling one at a time, to check the compatibility. And even with bs2defs.bas included, compiler gives error on "Faults var nib".

    I have PBP3

    Hardware is PIC16F870

  10. #10
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: Basic stamp code does not works.

    pbp3 has no var type of nibble as previously mentioned use type BYTE

    are you sure that code is for a max31855 ?
    because that code reads the chip temp not the THERMOCOUPLE temp

  11. #11
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Basic stamp code does not works.

    Yes, it works just fine on BS2. The code reads both data, I just enabled single one, to see if problem is in reading.

  12. #12


    Did you find this post helpful? Yes | No

    Default Re: Basic stamp code does not works.

    Try setting your TRIS register.

  13. #13
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Basic stamp code does not works.

    It took me two days to figure out

    when connecting to BS2, I was reversing the pins, so pinout in code was correct for that code only. Everything works just fine, thanks!

  14. #14
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: Basic stamp code does not works.

    Well I mentionned pins in my post and I was first to reply so I'm taking credit for solving this.

    Robert

Similar Threads

  1. Newbie migrating from Basic Stamp to PIC
    By gertlind in forum PBP3
    Replies: 7
    Last Post: - 2nd October 2013, 18:46
  2. Moving from Basic Stamp and MIKROE basic to PicBasic PRO
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 40
    Last Post: - 6th March 2013, 05:27
  3. Yet another SERIN2 problem - Conversion from Basic Stamp
    By Fanias in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 24th October 2012, 07:08
  4. PicBasic Pro to Basic Stamp conversion?
    By Kirk Fraser in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th March 2011, 06:49
  5. Basic Stamp BS2 replacement?
    By tenaja in forum Schematics
    Replies: 5
    Last Post: - 17th November 2009, 17:27

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