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.

opening an ASM file and converting to Swordfish

Status
Not open for further replies.

MrDEB

Well-Known Member
Still hacking at learning Swordfish and want to decipher the attached files to swordfish and prg an 18F PIC
BUT how to open and read? This is an assembly listing.
 

Attachments

  • homemadesolderingstation_1304181663_SolderingStation_ASM_v1_4.zip
    7.4 KB · Views: 131
.asm files are just text files. Either rename the file to SolderingStation.txt or run up Wordpad and open the .asm file from the File menu.

The code is poorly commented, so understanding it might be tricky
 
Last edited:
found this in basic I think from here **broken link removed**

here is the complete file. I started trying to write a conversion. First needs a Max6675 module. Looking at the Mbasic to decipher what some of the code is. Looks kinda like Swordfish?



'Setup MAX6675 - Thermocouple
MAXData con c1 ' MAXpin7
MAXcs con c6 ' MAXpin6
MAXClock con c3 ' MAXpin5
MAXResult var word
THC var word ' degrees Celsius (* power of 10)
THF var word 'stores degrees F


Main:

low MAXcs ' select chip
shiftin MAXData,MAXClock,msbpost,[MAXResult\16] ' get data
high MAXcs ' start new data capture

THC= (MAXResult/32) ' Deg. C

THF= (((THC*18)/10)+32) 'Conversion to Deg. F


lcdwrite b5\b4, portb.nib0,[SCRRAM,clear,"Temperature: ", dec THF, "F"] 'display temp. on LCD

pause 20 'give time between read cycles for MAX6675 to work right

goto Main


/**************************************************************************************
* max6675.c - communicates with a MAX6675 thermcouple interface chip *
* Copyright Jimbob's Ma 2006 *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation version 2 *
* of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
**************************************************************************************/

/*
This is a diver for the MAX6675 K-type thermocouple interface chip. It implements an SPI
bus without the need for dedicated hardware (aka a bit-banged interface). The result from
toFloat_TC() is the temperature in degrees celcius of the thermocouple tip. The rest should
be self-evident. Have a look at the end of the file for example usage.
*/

#ifndef TC_CLK
#define TC_CLK PIN_B1 //edit these pins as necessary
#endif

#ifndef TC_CS
#define TC_CS PIN_B2
#endif

#ifndef TC_DATA
#define TC_DATA PIN_B3
#endif


int1 thermocouple_error; //a handy dandy global error flag to tell you if a thermocouple is connected or not

void init_TC(void)
{
output_low(TC_CLK);
output_low(TC_DATA);
output_high(TC_CS); //if we idle high, the chip keeps doing conversions. Change this if you like
}

int16 read_TC(void) //It takes 200ms (ish) for the MAX6675 to perform a conversion
{
int8 i;
int16 data;

output_low(TC_CS); //stop any conversion processes
delay_us(1); //and give it some time to power up (not very much, admittedly)

for (i=0;i<16;i++){
shift_left(&data,2,input(TC_DATA)); //reads in 2 bytes to data from the pin TC_DATA
output_high(TC_CLK);
output_low(TC_CLK);
}

thermocouple_error=bit_test(data,2); //this is the thermocouple status bit

output_high(TC_CS);
return(data);
}

int16 sortout(int16 raw)
{
return(0x0FFF & (raw>>3)); //returns only the bits converning temperature
}

float toFloat_TC(int16 tmp)
{
return((float)tmp/4.0); //adjusts data to floating point format, and accounts for the decimal point
}

float do_everything(void)
{
init_TC();
delay_ms(200); //200ms is a long time to be doing nothing. use a timer interrupt to avoid wasting time here
return(toFloat_TC(sortout(read_TC())));
}


/*

//example program

#define TC_CLK PIN_B2
#define TC_CS PIN_B2
#define TC_DATA PIN_B1

#include "max6675.c"

void main()
{
char msg[32];
delay_ms(50); //allow oscillator to stabilise

while(1){
delay_ms(800);
sprintf(msg,"%01.2f%cC\r\n",do_everything(),0xB0);

if(thermocouple_error)
printf("Thermocouple not connected\r\n");
else
printf("%s",msg);
}
}

*/
 
here is what I have started

wonder if using the Swordfish SPI module would be a better idea?
the orginal was done in Mbasic. NEEDS lots of editing
Code:
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 6/26/2011                                                      *
*  Version : 1.0                                                            *
*  Notes   : max 6675 1st revision to convert from Mbasic to Swordfish
6/26/2011                                                               *
*          :                                                                *
*****************************************************************************
}
Max_Data portc.1
Max_cs portc.6
Max_Clock portc.3
Max_result as var word
THC as word              // temp conversions Celsius power of 10
THF as word              // stores degrees F

Low Max_cs               //chip select
shiftin Max_Data, Max_Clock, msbpost, (Max_result/16) // get data
high Max_cs                //start new data capature
THC = (Max_result/32)       //Celsius
THF = (((THC*18)/10)+32)    //convert to F
lcd.write "temperature" dec to str THF  //need to include LCD module
delayms(500)

//8888888888888888888888888888888888888888888888888888888888
//max6675 communicates w/ thermocouple

dim portb.1 as TC_CLK,
portb.2=TC_CS
portb.2=TC_DATA
outputlow(TC_CLK)
outputlow(TC_DATA)
outputlow(TC_CS)
// idle chip high
int8
int16 data
output low(TC_CS        // stop conversion
delayus(10)
for (i=0:i<16:i++)
    shift_Left(&data,2,input(TC_DATA))   //reads two bytes to data from pin TC_DATA
    output high(TC_CLK)
    output low(TC_CLK)
    thermocouple_error=bit_test(data,2)  //thermocouple status bit
    output high (TC_CS)
    return(data)
    int16 sortout(int16 raw)
    return(0x0fff & raw>>33)    // returns only bits converting temperature 
    float tofloat_TC(int16 tmp)
        return((float) tmp/4.0)  //adjusts data to floating point format (decimal point)
        float do_everything(void)
            init_TC()
                delayms(200)
 
Just had a thought!!!
seeing how the MAX6675 measures the room temp then substracts it from the thermocouple temp what would happen if one used a DS18B20 to measure room temp thus avoiding any heat from power supply?
Then input the thermocouple voltage to ADC port, convert to a temperature and substract the room temperature. The thermocouple output has a very large resolution and using the chart for typr K device to display liquid temp??JUST a theory??
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top