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.

PIC16F628A Question

Status
Not open for further replies.
(in assembly)
Providing each CALL has a return at the end of it, is it possible to have endless CALL's inside CALL's?

Or will the program get lost. Does this have something to do with the stack?
 
The stack can only hold 8 addresses and so you can only have 8 nested calls. If you use interrupts this becomes worse. The interrupt itself uses 1 stack location and any calls from the interrupt further locations.

Mike.
 
(in assembly)
Providing each CALL has a return at the end of it, is it possible to have endless CALL's inside CALL's?

Or will the program get lost. Does this have something to do with the stack?

Only a small number of calls, which means it's VERY advisible not to use subroutine calls within ISR's, or if you do, keep them strictly to a very low number. Once you run out of stack your program is doomed! - anything can happen, and if it's caused by interrupot routines, it's VERY, VERY difficult to fault find.
 
In your flashing LED program, you don't have to do this to the Status register:
Bit RP1 starts with zero so all you have to do is set or clear RP0 to change from bank0 to bank1.

BCF STATUS, RP1 ; Bank 1
BSF STATUS, RP0 ; Bank 1
MOVLW B'11100001' ; RA<7:6>, Inputs. RA<5:2> Outputs. RA<1:0> Inputs.
MOVWF TRISA ;

MOVLW B'11110011' ; RB<7:4> Inputs. RB<3:2> Ouputs. RB<0:1> Inputs.
MOVWF TRISB ;

BCF STATUS, RP1 ; Bank 0
BCF STATUS, RP0 ; Bank 0
 
In your flashing LED program, you don't have to do this to the Status register: .........
Yeah I am aware, I know its a waste of an instruction but I like to use that 2 line expression. When switching banks constantly its just handy (for me) to see what state each bit is in when fault finding. One could argue a bad habbit, ... ar well

See your Telephone Ring Detector:
There is absolutely no point in putting a 20v zener diode on the phone line.
It's getting a little off topic, but please, expand. I am no professional and like being corrected when wrong. Its how I learn.
My answer is, I saw it, I built it, I worked, so I left it.
 
Last edited:
Thanks very much nigel...
Once you run out of stack your program is doomed!
I fear this is what is happening with my program.
My program is doing 2 things;
- communicating with the DS18B20 and getting temperature data, and,
- converting the data to decimal and displaying it on a 3 digit 7 segment LED.
When I cut it in half and run it a 2 separate programs, It works perfectly. But when I try and run it as one, poo hits the fan.

Is there any easy way of "seeing the stack" and seeing it (possibly in my case) overflow?
 
Last edited:
Thanks very much nigel...

I fear this is what is happening with my program.
My program is doing 2 things;
- communicating with the DS18B20 and getting temperature data, and,
- converting the data to decimal and displaying it on a 3 digit 7 segment LED.
When I cut it in half and run it a 2 separate programs, It works perfectly. But when I try and run it as one, poo hits the fan.

Is there any easy way of "seeing the stack" and seeing it (possibly in my case) overflow?

I presume the MPLAB simulator keeps track of it?, but I never use it myself.

However, it's pretty easy to just go through your program and keep count of how many nested subroutines you use.

I seem to recall you are using multiple tables?, are you trying to use a table that crosses a 256 byte boundary?, that way lies disaster as well.
 
Last edited:
Is there any easy way of "seeing the stack" and seeing it (possibly in my case) overflow?

hi,
If you wish, post your full program I will run it with Oshonsoft, it has STACK warnings and history.
 
I seem to recall you are using multiple tables?, are you trying to use a table that crosses a 256 byte boundary?, that way lies disaster as well.
No, The DIGIT_DECIMAL table only has 10 instructions, and the DIGIT_ONES and DIGIT_TENS both has 99 instructions each beacuse thats all I can display. No point going furthur if i cant display it.

hi,
If you wish, post your full program I will run it with Oshonsoft, it has STACK warnings and history.
(The code is too long to paste here so I have placed it here, click to view. PIC16F628A - DS18B20 Digital Thermometer)

Note I haven't got around to using interrupts to continually update the temperature and refresh the display. This program gets the temp and multiplexs the display once only. Well, its suppose to.
 
Put SetUp and all other sub-routines below "tables" so that the 3 tables are as high as possible in your program so that they do not cross the 256 byte border. You have absolutely no idea where the last retlw will be on the page, with your layout.


You don't need

RETURN
as the last instruction in your table.

What detection do you have to detect the last byte in a table?
 
Last edited:
Thanks colin.
But I have come to realise that I am using table in the wrong mannor.
I should just be using 1 table to call the arrangement for the 7 segment display, therefore the table will only need to have 10 instructions.
I should be using math to convert my 12-bit number to decimal, then only call a table for the display arrangement.

Problem is, I'm stuck trying to do the math with assembly.

This post started out as a 'Stack' question but has turned into the same topic as another one of my posts. My apologies for this. It can be found here... https://www.electro-tech-online.com/threads/pic16f628a-temp-sensor-7-seg-multiplexing-issue.107446/
 
What maths are you trying to do?

Well, This is my objective:

It is a temperature sensor project with the direct to digital DS18B20.
I am getting a 12-bit result out of the sensor.
With incrments/resolution of 0.0625 degrees C.
See attachment for temperature/data relationship.

So I have a 11 bit number (MSB is a sign bit 0 = positive 1 = negative) that i wish to display on a multiplexed 7 segment display. 2 digits + 1 decimal.
 

Attachments

  • Table1 Temperature-Data Relationship.jpg
    Table1 Temperature-Data Relationship.jpg
    164 KB · Views: 182
  • Schematic.jpg
    Schematic.jpg
    140 KB · Views: 173
Firstly you work out what range you want: 00 degrees C to 99 degreesC.
Each degree is 1 0000 in binary.
Shift the 12 bit number 4 times right to get each degree in binary. Remome the highest bit.
Convert the number to BCD and output to the two displays via a single 0 to 9 table
 
Firstly you work out what range you want: 00 degrees C to 99 degreesC.
Each degree is 1 0000 in binary.
Shift the 12 bit number 4 times right to get each degree in binary. Remome the highest bit.
Convert the number to BCD and output to the two displays via a single 0 to 9 table
Ok, thats half solved.
What about the decimal place
 
This is for the decimal place:

Code:
DECIMAL  HEXADECIMAL  TEMPERATURE-EQUIV  NUMBER-TO-DISPLAY
   0        0000           0                  0
   1        0001           0.0625             0.1
   2        0010           0.1250             0.1
   3        0011           0.1875             0.2
   4        0100           0.2500             0.3
   5        0101           0.3125             0.3
   6        0110           0.3750             0.4
   7        0111           0.4375             0.4
   8        1000           0.5000             0.5
   9        1001           0.5625             0.6
  10        1010           0.6250             0.6
  11        1011           0.6875             0.7
  12        1100           0.7500             0.8
  13        1101           0.8125             0.8
  14        1110           0.8750             0.9
  15        1111           0.9375             0.9
 
You said you had 2 digits. Why do you want a decimal place for temperatures from zero degress to 9 degrees?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top