PDA

View Full Version : Making a menu



chrisshortys
- 17th October 2008, 16:04
Hi there, im currently trying to create a menu on a LCD display which im having some troubles with. Ill post m code further down but the code seems to be running straight through and then freezing with "game length" on the top and the minutes on the bottom. I guess ive missed somthing but for all the time ive spent looking i can't see the problem!
Cheers


Also i forgot to mention it is possible to change one of the values on the timer if you rapidly press the button as it turns on then after this i get no responce!


' Hardware Defines
' ================

CMCON=%00000111
CVRCON=%00000000
'
' LCD Display
' -----------
' Adjust these to suit your chosen LCD pinout
'
DEFINE LCD_DREG PORTB 'Define PIC port used for LCD Data lines
DEFINE LCD_DBIT 4 'Define first pin of portb connected to LCD DB4
DEFINE LCD_RSREG PORTB 'Define PIC port used for RS line of LCD
DEFINE LCD_RSBIT 3 'Define Portb pin used for RS connection
DEFINE LCD_EREG PORTB 'Define PIC prot used for E line of LCD
DEFINE LCD_EBIT 0 'Define PortB pin used for E connection
DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
DEFINE LCD_LINES 2 'Define using a 2 line LCD
DEFINE LCD_COMMANDUS 2000 'Define delay between sending LCD commands
DEFINE LCD_DATAUS 50 'Define delay time between data sent.

' Control Buttons/Lines
' ---------------------
ButStart var Portc.0 ' Take this pin low momentarily to START timing
ButStop var Portc.1 ' Take this pin low momentarily to STOP timing
ButReset var Portc.2 ' Take this pin low momentarily to RESET clock
Butup var portc.3 ' Take this pin low momentarily to increase clock time
Butdwn var portc.4 ' Take this pin low momentarily to decrease clock time
'
' Software Defines
' ----------------
BannerOffset var BYTE ' Variable holding start address of Banner Display
CounterA var BYTE ' Just a Counter
CounterB var BYTE ' Just a Counter
CounterC var BYTE
DataA var BYTE
Hours var BYTE
Hundredths var BYTE
Minutes var BYTE
OverflowError var BIT
RunningFlag var BIT
Seconds var BYTE
SetupTimeOut var WORD ' Timeout counter for Calibration/Set-Up Mode
TMR1Cal var BYTE ' Calibration Value
IHOURS VAR BYTE
IMINUTES VAR BYTE

TMR1CalAR var Byte ' Calibration 0=ADVANCE, 1=RETARD
TMR1RunOn var WORD ' variable holding TMR1 Run-On value
'
' EEPROM Presets
' --------------
'Data @0,0 ' Advance/Retard Indicator
'Data 0 ' Calibration Value
'Data "Spec-ops.nl Tactical Game Aid - Enter Game Length"
'
' Software Constants
' ------------------

' Initialise Processor
' --------------------
TRISA=%00000000
TRISB=%00000000
TRISC=%00011111
ADCON0=%11000000
ADCON1=%00000111

' INITIAL Time Setup
'----------------------------
start:

IHOURS=0
IMINUTES=3



HOURSI:
If Butup=0 then
IHOURS=IHOURS+1
IF BUTDWN=0 THEN
IHOURS=IHOURS-1
IF BUTSTART=0 THEN
GOTO MINSI
ENDIF
ENDIF
ENDIF
GOSUB TIMESETUP

MINSI:
If Butup=0 then
IMINUTES=IMINUTES+1
IF BUTDWN=0 THEN
IMINUTES=IMINUTES-1
IF BUTSTART=0 THEN
GOTO CONTINUE
IF BUTRESET=0 THEN
GOTO HOURSI
ENDIF
ENDIF
ENDIF
ENDIF
GOSUB TIMESETUP


timesetup:

LCDOUT $FE, 1, "GAME LENGTH"
LCDOut $FE,$C0,DEC2 IHours,":",DEC2 IMinutes,":00.00"
PAUSE 200
REturn

'butup and butdwn


Continue:

LCDOUT $FE, 1, "Settings Saved"
pause 1000
goto continue
end

skimask
- 17th October 2008, 16:10
MINSI:
If Butup=0 then
IMINUTES=IMINUTES+1
IF BUTDWN=0 THEN
IMINUTES=IMINUTES-1
IF BUTSTART=0 THEN
GOTO CONTINUE
IF BUTRESET=0 THEN
GOTO HOURSI
ENDIF
ENDIF
ENDIF
ENDIF
GOSUB TIMESETUP

timesetup:
LCDOUT $FE, 1, "GAME LENGTH"
LCDOut $FE,$C0,DEC2 IHours,":",DEC2 IMinutes,":00.00"
PAUSE 200
REturn

Codes falls thru after the GOSUB, goes to timesetup, then tries to RETURN from which there was no GOSUB...therefore, the PIC dies a horrible death not knowing where to RETURN to.
Ok, not that horrible, and not a death, but it probably does stop dead in it's tracks.

chrisshortys
- 17th October 2008, 23:03
Ok so if i tried somthing like:

MINSI:
If Butup=0 then
IMINUTES=IMINUTES+1
IF BUTDWN=0 THEN
IMINUTES=IMINUTES-1
IF BUTSTART=0 THEN
GOTO CONTINUE
IF BUTRESET=0 THEN
GOTO HOURSI
ENDIF
ENDIF
ENDIF
ENDIF
GOSUB TIMESETUP
goto minsi

timesetup:
LCDOUT $FE, 1, "GAME LENGTH"
LCDOut $FE,$C0,DEC2 IHours,":",DEC2 IMinutes,":00.00"
PAUSE 200
Return
That should get that working?

skimask
- 17th October 2008, 23:07
That should get that working?

Have you tried it yet?

chrisshortys
- 17th October 2008, 23:10
I gave it a quick go and it appears to step through on +1 but does not on the -1 or the goto the next section of coding.
I was going to put it down to being up for 20 hours and not looking forward to the 7:30 start at work tommorow for it not working right now unless you have any ideas?

skimask
- 18th October 2008, 03:05
I was going to put it down to being up for 20 hours and not looking forward to the 7:30 start at work tommorow for it not working right now unless you have any ideas?
If you're going to program a PIC, you almost want to think like a PIC.
Go thru your program in your head, step by step, follow it thru and you'll see why it does what it does.
Don't assume it'll work because you want it to. A CPU follows instructions in an explicit order. It doesn't go off on it's own because it thinks it's the thing to do at the moment.

chrisshortys
- 19th October 2008, 23:14
well i went back to it, i stripped it right back to basics to ensure the buttons were working and tested it a command at a time and got it working!
It dint like the way i had used the IF and ENDIF commands...

start:

IHOURS=0
IMINUTES=3



HOURSI:
If Butup=0 then
IHOURS=IHOURS+1
endif
IF BUTdwn=0 THEN
IHOURS=IHOURS-1
ENDIF
IF BUTSTART=0 THEN
GOTO MINSI
ENDIF
pause 50
GOSUB TIMESETUP
GOTO HOURSI

MINSI:
PAUSE 5000
MINSI1:
IF BUTUP=0 THEN
IMINUTES=IMINUTES+1
ENDIF
IF BUTDWN=0 THEN
IMINUTES=IMINUTES-1
ENDIF
IF BUTRESET=0 THEN
GOTO HOURSI
ENDIF
IF BUTSTART=0 THEN
GOTO CONTINUE
ENDIF
PAUSE 50
GOSUB TIMESETUP
GOTO MINSI1


timesetup:
pause 50
LCDOUT $FE, 1, "GAME LENGTH"
LCDOut $FE,$C0,DEC2 IHours,":",DEC2 IMinutes,":00.00"
PAUSE 50
REturn

'butup and butdwn


Continue:

LCDOUT $FE, 1, "Settings Saved"
LCDOut $FE,$C0,DEC2 IHours,":",DEC2 IMinutes,":00.00"
pause 6000
goto continue
end

So with that fully working i plonked it back into the other code im working on and now it freezes again doing what the original coding did and getting lost after adding the first hour....
More time to play around tommorow night i guess.

skimask
- 19th October 2008, 23:47
Well, that's obviously not the full code so we can't help you figure out what's causing the lock-up...

chrisshortys
- 20th October 2008, 18:10
Well i didn't post it for a reason you see. I wanted to try and solve the problem myself. It's all well and good me using the forums for help but if i dont try and dont some on my own im never going to progress!
This was one thing i was majorly criticised over by a previous line manager, not knowing when to ask for help and trying to do it all myself so now im trying to find a happy medium.

Anyway now back to the project!
I got the code working by going through line by line and rebuilding it in the main project :) thats all good but.... i now have a new error off MPLAB when i try and compile the coding:

"Operand contains unresolvable labels or is too complex"

Any idea on what this means guys?

skimask
- 20th October 2008, 18:18
Well i didn't post it for a reason you see. I wanted to try and solve the problem myself. It's all well and good me using the forums for help but if i dont try and dont some on my own im never going to progress!
Somebody should 'sticky' that statement and make it required reading for newbies...

This was one thing i was majorly criticised over by a previous line manager, not knowing when to ask for help and trying to do it all myself so now im trying to find a happy medium.
Anyway now back to the project!
I got the code working by going through line by line and rebuilding it in the main project :) thats all good but.... i now have a new error off MPLAB when i try and compile the coding:
"Operand contains unresolvable labels or is too complex"
Any idea on what this means guys?
Is that the FULL error or are there extra numbers that go with it? If there are numbers, they may point to either a line in the original source code, or, if using MPASM, the assembly listing as to where the error has occured. I think in this case, it might be simply a misplaced space or extra ' or " somewhere in there, a punctuation thing.
Otherwise, post the code :)

chrisshortys
- 20th October 2008, 18:34
Its the error code from the compillier from asm to hex in mplabs. This is the full error code


Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F688 "OLYMPICS.ASM" /l"OLYMPICS.lst" /e"OLYMPICS.err" /o"OLYMPICS.o"
Warning[215] C:\PBP\16F876A.INC 20 : Processor superseded by command line. Verify processor symbol.
Message[301] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F876A.INC 36 : MESSAGE: (Processor-header file mismatch. Verify selected processor.)
Error[151] C:\PBP\PBPPIC14.LIB 7421 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 571 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 587 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 604 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 607 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 613 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 571 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 587 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 604 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 607 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 613 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 517 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 522 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 529 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 517 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 522 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 529 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 637 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 643 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 659 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 676 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 679 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 685 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 571 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 587 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 604 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 607 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 613 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 517 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 522 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 529 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 517 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 522 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 529 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 637 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 643 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 659 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 676 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 679 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 685 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 517 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 522 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 529 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 517 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 522 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 529 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 517 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 522 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 529 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 517 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 522 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 529 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 517 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 522 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 529 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 517 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 522 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 529 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 517 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 522 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 529 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 517 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 522 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 529 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 571 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 587 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 604 : Operand contains unresolvable labels or is too complex
Error[151] C:\PBP\OLYMPICS.ASM 607 : Operand contains unresolvable labels or is too complex

BUILD FAILED: Mon Oct 20 18:03:13 2008



So from what you said its proberly just a coding error somwhere, I shall go and have a look in the coding again!
Was just making sure that the error didn't mean i had used up all of the memory on the chip, its getting a bit long now at 468 lines! Ive never had such a large projet so i dont know what happens when you fill the chip up to the brim!

Breaking the forum too now! got The text that you have entered is too long (174172 characters). Please shorten it to 10000 characters long.
come up when i tried to post :p so had to chop the code but you get the idea!

skimask
- 20th October 2008, 18:37
Looks to me like you've got one PIC selected for compiling/assembling, but have the code written for another PIC.



Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F688 "OLYMPICS.ASM" /l"OLYMPICS.lst" /e"OLYMPICS.err" /o"OLYMPICS.o"
Warning[215] C:\PBP\16F876A.INC 20 : Processor superseded by command line. Verify processor symbol.
Message[301] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\P16F876A.INC 36 : MESSAGE: (Processor-header file mismatch. Verify selected processor.)



Was just making sure that the error didn't mean i had used up all of the memory on the chip, its getting a bit long now at 468 lines! Ive never had such a large projet so i dont know what happens when you fill the chip up to the brim!
My latest project is up to 5,600 lines now. I'd guess another 4,000 or so to go. MCS and/or PBP and/or MPLAB will let you know when it gets too long.

chrisshortys
- 20th October 2008, 18:43
ok now thats just weird!

I hadnt changed anything for that to happen......

I just went through the programe and commented out all the code i added and removed the comments one by one and it compilied fine........

I must be being haunted or somthing :s

But thanks alot for your time!

It's good to know im not runnign out of space just yet! I had a look at those youtube vids of your latest project the other day and they realy are scary the amount of work and knowledge in them!

chrisshortys
- 29th October 2008, 17:07
Well i ran out of memory at around 700 lines :(
Now the code i have at the moment isn't that far but im getting close!
so i'm after any advice on the code i have on ways of doing the same thing without using as much memory!
Would using tables on menus help reduce space as i still have ALOT of coding to do!
I know the code is quite fragmented and not well ordered but I had planned to rewrite it its just me making a beta of it at the moment!

cheers!


' ' Olympic Timer
' =============
' Melanie Newman
' 05/Aug/2004
' Modified by Chris Hammersley
' For Spec-ops.nl
' Oct 2008
' Topical Program demonstrates use of Interrupt
' Driven Background TIMER, to time events down to
' one one-hundredth of a Second (1/100 Sec).
'
' Bonus CALIBRATION Feature allows simple adjustments
' in 360mS steps per hour. This calibration adjustment
' range is limited to +/- 36 seconds per Hour.
'
' This program is for 4MHz clock (1uS Timer Ticks).

'Original programe includes a calibratable stop clock counting upwards.

'MODIFICATIONS
'-------------
'V1.1 23rd october 2008
'Working menu selecting game length with 2 presets and a customisable
'Count down clock.
'Programe knows when time is up and goto new instructions.
' PIC Defines
'
'
'V1.2 Ongoing
'GAME TYPES MENU INCLUDED
'INCLUDED THE CODING FOR BOTH COUNT-DOWN AND COUNT-UP CLOCKS
'
'V1.3 FUTURE
'INCLUDE RF OPERATIONS
'
' ===========
'
' Change these defines to suit your chosen PIC
'
'@ DEVICE pic16F876a, WDT_ON ' Watchdog Timer
'@ DEVICE pic16F876a, PWRT_ON ' Power-On Timer
'@ DEVICE pic16F876a, BOD_ON ' Brown-Out Detect
'@ DEVICE pic16F876a, LVP_OFF ' Low-Voltage Programming
'@ DEVICE pic16F876a, CPD_OFF ' Data Memory Code Protect
'@ DEVICE pic16F876a, PROTECT_OFF
' Program Code Protection
'@ DEVICE pic16F876a, WRT_OFF ' Flash Memory Word Enable

'
' Hardware Defines
' ================

CMCON=%00000111
CVRCON=%00000000
'
' LCD Display
' -----------
' Adjust these to suit your chosen LCD pinout
'
DEFINE LCD_DREG PORTB 'Define PIC port used for LCD Data lines
DEFINE LCD_DBIT 4 'Define first pin of portb connected to LCD DB4
DEFINE LCD_RSREG PORTB 'Define PIC port used for RS line of LCD
DEFINE LCD_RSBIT 3 'Define Portb pin used for RS connection
DEFINE LCD_EREG PORTB 'Define PIC prot used for E line of LCD
DEFINE LCD_EBIT 0 'Define PortB pin used for E connection
DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
DEFINE LCD_LINES 2 'Define using a 2 line LCD
DEFINE LCD_COMMANDUS 2000 'Define delay between sending LCD commands
DEFINE LCD_DATAUS 50 'Define delay time between data sent.

' Control Buttons/Lines
' ---------------------
ButStart var Portc.0 ' Take this pin low momentarily to START timing
ButStop var Portc.1 ' Take this pin low momentarily to STOP timing
ButReset var Portc.2 ' Take this pin low momentarily to RESET clock
Butup var portc.3 ' Take this pin low momentarily to increase clock time
Butdwn var portc.4 ' Take this pin low momentarily to decrease clock time
'
' Hold the RESET Button pressed for at least FIVE seconds
' to jump into CALIBRATION Mode
'
' Software Defines
' ----------------
BannerOffset var BYTE ' Variable holding start address of Banner Display
CounterA var BYTE ' Just a Counter
CounterB var BYTE ' Just a Counter
CounterC var BYTE
DataA var BYTE
Hours var BYTE
Hundredths var BYTE
Minutes var BYTE
OverflowError var BIT
RunningFlag var BIT
Seconds var BYTE
SetupTimeOut var WORD ' Timeout counter for Calibration/Set-Up Mode
TMR1Cal var BYTE ' Calibration Value
IHOURS VAR BYTE
IMINUTES VAR BYTE
TIMER VAR BYTE

TMR1CalAR var Byte ' Calibration 0=ADVANCE, 1=RETARD
TMR1RunOn var WORD ' variable holding TMR1 Run-On value
'
' EEPROM Presets
' --------------
Data @0,0 ' Advance/Retard Indicator
Data 0 ' Calibration Value
Data "Spec-ops.nl Tactical Game Aid - Enter Game Length"
'
' Software Constants
' ------------------
TMR1CalMax con 100 ' Maximum adjustment (+/-100uS per 10mS interrupt)
TMR1Preset con $D910 ' 10mS Timer Reload value, offset by 20uS
' to allow for TMR1 Setting Calculations
'
' Start Program
' =============
'
' Initialise Processor
' --------------------
TRISA=%00000000
TRISB=%00000000
TRISC=%00011111
ADCON0=%11000000
ADCON1=%00000111
OPTION_REG.7=0 ' Enable Pull-Up's
RunningFlag=0 ' Disable actual Interrupt Time-Keeping
Pause 1000 ' Pause for LCD to initialise
'
' Silly Intro Banner just for Fun
' -------------------------------
LCDOut $FE,1 ' Clear LCD
BannerOffset=2:Gosub DisplayBanner
Pause 2000
For CounterA=0 to 33
BannerOffset=2+CounterA
Gosub DisplayBanner
Pause 350 'pause between change of characters
Next CounterA
Pause 4000
'----------------
'Menu and Presets
'----------------
'
'MAIN MENU
'---------
MAINMENU:
PAUSE 1000

MAINMENUA:
LCDOUT $FE, 1, " SELECT MENU"
LCDOut $FE,$C0,"COUNTDOWN"
PAUSE 100
IF BUTSTART=0 THEN
GOTO MENUA
ENDIF
IF BUTUP=0 THEN
GOTO MAINMENUB
ENDIF
GOTO MAINMENUA

MAINMENUB:
LCDOUT $FE, 1, " SELECT MENU:"
LCDOut $FE,$C0," COUNT UP"
PAUSE 100
IF BUTDWN=0 THEN
GOTO MAINMENU
ENDIF
IF BUTSTART=0 THEN
TIMER=1
PAUSE 20
IF BUTSTART=0 THEN
GOTO BEGINNING
ENDIF
ENDIF
PAUSE 50
GOTO MAINMENUB

chrisshortys
- 29th October 2008, 17:07
Second half of code


'COUNTDOWN MENU
'--------------

MenuA:
PAUSE 1000
TIMER=0

MENUCD:
LCDOUT $FE, 1, " Preset 1"
LCDOut $FE,$C0,"00:30:00.00"
pause 100
IF BUTSTART=0 THEN
GOTO preset1
ENDIF
IF BUTDWN=0 THEN
GOTO CUSTOMA
ENDIF
IF BUTUP=0 THEN
GOTO PRESET2
ENDIF
IF BUTRESET=0 THEN
GOTO MAINMENU
ENDIF
GOTO MENUCD

CUSTOMA:
PAUSE 1000
CUSTOMB:
LCDOUT $FE, 1, "CUSTOM TIME"
LCDOut $FE,$C0,"ENTER A CUSTOM TIME"
PAUSE 100
IF BUTSTART=0 THEN
GOTO CUSTOM
ENDIF
IF BUTDWN=0 THEN
GOTO PRESET2
ENDIF
IF BUTUP=0 THEN
GOTO MENUCD
ENDIF
IF BUTRESET=0 THEN
GOTO MAINMENU
ENDIF
PAUSE 50
GOTO CUSTOMB
'----------------------------
PRESET1:
PAUSE 1000
PRESET1A
LCDOUT $FE, 1, "Accept Preset 1?"
LCDOut $FE,$C0,"00:30:00.00"
PAUSE 100

IF BUTSTART=0 THEN
GOTO PRESET1set
ENDIF
IF BUTRESET=0 THEN
GOTO MENUCD
ENDIF
GOTO PRESET1A

PRESET1SET:
IHOURS=0
IMINUTES=30
PAUSE 50
GOTO CONTINUE
'---------------------------
PRESET2:
PAUSE 1000
PRESET2A
LCDOUT $FE, 1, " Preset 2"
LCDOut $FE,$C0,"00:45:00.00"
PAUSE 100
IF BUTSTART=0 THEN
GOTO PRESET2A
ENDIF
IF BUTUP=0 THEN
GOTO CUSTOMA
ENDIF
IF BUTDWN=0 THEN
GOTO menuCD
ENDIF
IF BUTRESET=0 THEN
GOTO MAINMENU
ENDIF
GOTO PRESET2A

PRESET2B:
PAUSE 1000
PRESET2C
LCDOUT $FE, 1, "Accept Preset 2?"
LCDOut $FE,$C0,"00:45:00.00"
PAUSE 100

IF BUTSTART=0 THEN
GOTO PRESET2SET
ENDIF
IF BUTRESET=0 THEN
GOTO MENUCD
ENDIF
GOTO PRESET2C

PRESET2SET:
IHOURS=0
IMINUTES=45
PAUSE 50
GOTO CONTINUE

'
' Custom Time Setup
'----------------------------
CUSTOM:
PAUSE 1000

IHOURS=0
IMINUTES=3

HOURSI:
If Butup=0 then
IHOURS=IHOURS+1
endif
If BUTDWN=0 THEN
IHOURS=IHOURS-1
ENDIF
IF BUTSTART=0 THEN
GOTO MINSA
ENDIF
IF BUTRESET=0 THEN
GOTO MENUA
ENDIF
pause 50
GOSUB TIMESETUP
GOTO HOURSI

MINSA:
PAUSE 1000

MINSI:
IF BUTUP=0 THEN
IMINUTES=IMINUTES+1
ENDIF
IF BUTDWN=0 THEN
IMINUTES=IMINUTES-1
ENDIF
IF BUTRESET=0 THEN
GOTO HOURSI
ENDIF
IF BUTSTART=0 THEN
GOTO CONTINUE
ENDIF
PAUSE 50
GOSUB TIMESETUP
GOTO MINSI


timesetup:
pause 50
LCDOUT $FE, 1, "GAME LENGTH"
LCDOut $FE,$C0,DEC2 IHours,":",DEC2 IMinutes,":00.00"
PAUSE 50
REturn


Continue:

LCDOUT $FE, 1, "Settings Saved"
LCDOut $FE,$C0,DEC2 IHours,":",DEC2 IMinutes,":00.00"
pause 6000


BEGINNING
'
' Initialise TMR1 Interrupts**************************************** ************************************************** *
' --------------------------
Gosub SetTimer ' Set the Timer for next 10mS Interrupt
IF TIMER=1 THEN
On Interrupt goto TickCountUP
ELSE
On Interrupt goto TickCount
ENDIF
PIE1.0=1 ' Enable TMR1 Interrupts
INTCON.6=1 ' Enable all unmasked Interrupts
INTCON.7=1 ' Enable Global Interrupts
'
' -----------------------------------------------------
' Following the above "On Interrupt", no Basic Command
' is allowed that takes more than 10mS to execute
' otherwise the 10mS Interrupt interval is compromised.
' -----------------------------------------------------
'
' Reset Timer Variables for Start
' -------------------------------
DisplayReset:
LCDOut $FE,1 ' Clear LCD
Read 0,TMR1CalAR ' Read Calibration Advance/Retard Indicator
Read 1,TMR1Cal ' Read Calibration Value
Hundredths=0 ' Reset Timer Counter variables
Seconds=0
Minutes=IMINUTES
Hours=IHOURS
OverflowError=0
'
' Main Program Loop
' =================
Enable
DisplayLoop:
If ButStart=0 then RunningFlag=1
If ButStop=0 then RunningFlag=0
LCDOut $FE,$80,DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds,".",DEC2 Hundredths

If OverflowError=1 then
If Seconds.0=1 then
LCDOut $FE,$8C,"ERR"
else
LCDOut $FE,$8C," "
endif
endif
If RunningFlag=1 then goto DisplayLoop
If ButReset=1 then goto DisplayLoop
Disable
'
' Reset Clock
' ===========
' Momentarily Press the Reset Button for RESET action.
' Continue holding the Reset Button for MORE than 5 seconds
' to jump into Calibration/Set-Up Mode
'
ResetClock:
LCDOut $FE,1,"Reset OK"
Pause 1000
Seconds=1
While Seconds < 5
Pause 1000
If ButReset=1 then goto DisplayReset
Seconds=Seconds+1
Wend
'
' Calibration Adjustment
' ======================
' If No Button is Pressed for 20 Seconds, then the program
' will automatically exit Calibration/Set-Up Mode WITHOUT saving
' any new values.
'
SetUpTimeout=0
Calibration:
LCDOut $FE,1,"Calibrate: "
While ButReset=0:Wend ' Wait for User to release finger
CalibrationLoop:
LCDOut $FE,$8B
If TMR1Cal=0 then
LCDOut " "
else
If TMR1CalAR=0 then
LCDOut "+"
else
LCDOut "-"
endif
endif
LCDOut #TMR1Cal," "
' ----------------------------------------------------------
' Press Start Button to ADVANCE (speed-up) Clock
' Press STOP Button to RETARD (slow-down) Clock
' Press RESET Button to SAVE new Calibration Setting
' ----------------------------------------------------------
' Remember each Calibration 'tick' will advance or
' retard the Timing by 1uS in every 10mS period - that's
' 360mS/Hour per setting. Example: A setting of +8 will
' SPEED-UP the Timer by 2.88 Seconds (8 x 360mS) in an Hour.
' ----------------------------------------------------------
If TMR1CalAR=0 then
If ButStart=0 then Gosub CalAdvance
If ButStop=0 then Gosub CalRetard
else
If ButStart=0 then Gosub CalRetard
If ButStop=0 then Gosub CalAdvance
endif
If ButReset=0 then
Write 0,TMR1CalAR
Write 1,TMR1Cal
LCDOut $FE,1,"Have a Nice Day"
Pause 1000
Goto DisplayReset
endif
SetupTimeout=SetupTimeout+1
If SetupTimeout>200 then goto DisplayReset
Pause 100
Goto CalibrationLoop

'
' Subroutine Increments Calibration Value
' ---------------------------------------
CalAdvance:
SetupTimeout=0
If TMR1Cal=>TMR1CalMax then
TMR1Cal=TMR1cALmAX
TMR1CalAR=TMR1CalAR^1
else
TMR1Cal=TMR1Cal+1
endif
Return
'
' Subroutine Decrements Calibration Value
' ---------------------------------------
CalRetard:
SetupTimeout=0
If TMR1Cal=0 then
TMR1Cal=1
TMR1CalAR=TMR1CalAR^1
else
TMR1Cal=TMR1Cal-1
endif
Return
'
' Subroutine Displays Banner Intro
' --------------------------------
DisplayBanner:
CounterC=BannerOffset+15
LCDOut $FE,$80
For CounterB=BannerOffset to CounterC
Read CounterB,DataA
LCDOut DataA
Next CounterB
Return
'
' Subroutine Loads TMR1 values
' ============================
SetTimer:
T1CON.0=0 ' Stop the Clock
TMR1RunOn.Highbyte=TMR1H ' Load the Run-On (Over-Run) value (if any)
TMR1RunOn.Lowbyte=TMR1L
TMR1RunOn=TMR1Preset+TMR1RunOn
' Calculate the New (adjusted) value for TMR1
If TMR1CalAR=0 then ' Calibration ADVANCE (add) or RETARD (subtract)
TMR1RunOn=TMR1RunOn+TMR1Cal
else
TMR1RunOn=TMR1RunOn-TMR1Cal
endif
TMR1H=TMR1RunOn.Highbyte ' Save new values to TMR1
TMR1L=TMR1RunOn.Lowbyte
T1CON.0=1 ' Restart the Clock
PIR1.0=0 ' Reset TMR1's Interupt Flag
Return
'
' Timer Interrupt Handler
' =======================
TickCount:
Gosub SetTimer ' Set the Timer for next 10mS Interrupt
If RunningFlag=1 then ' If timing actually enabled... then...

IF HUNDREDTHS=0 THEN
IF SECONDS=0 THEN
IF MINUTES=0 THEN
IF HOURS=0 THEN
GOTO TIMEUP
ENDIF
ENDIF
ENDIF
ENDIF


If seconds=0 then
hundredths=0
'goSUB timeup
else
Hundredths=Hundredths-1
' Increment 10mS Seconds Counter
If Hundredths=0 then
Hundredths=99
seconds=seconds-1
endif
endif

' Increment the Seconds

If minutes>0 then

If Seconds=0 then
Seconds=59
minutes=minutes-1
endif
endif


If hours>0 then

If Minutes=0 then
Minutes=59
hours=hours-1
endif
endif

If Hours>99 then
' Handle any Overflow
Hours=0
OverFlowError=1
endif
endif
Resume

timeup:
LCDOUT $FE,$C0
LCDOUT "Time is up"
GOTO timeup

TickCountUP:
Gosub SetTimer ' Set the Timer for next 10mS Interrupt
If RunningFlag=1 then ' If timing actually enabled... then...
Hundredths=Hundredths+1
' Increment 10mS Seconds Counter
If Hundredths>99 then
Hundredths=0
Seconds=Seconds+1
' Increment the Seconds
If Seconds>59 then
Seconds=0
Minutes=Minutes+1
' Increment the Minutes
If Minutes>59 then
Minutes=0
Hours=Hours+1
' Increment the Hours
If Hours>99 then
' Handle any Overflow
Hours=0
OverFlowError=1
endif
endif
endif
endif
endif
Resume
End

mister_e
- 29th October 2008, 17:09
If you have a load of Text screen/Menus, you have few choices

1. using a bigger PIC
2. using an external EEPROM to store your Text
3. use the following method --- http://www.pbpgroup.com/modules/wfsection/article.php?articleid=10

HTH

skimask
- 29th October 2008, 17:27
Well i ran out of memory at around 700 lines :(
When you say you ran out of memory, do you mean you ran out of code space or variable space?

Acetronics2
- 29th October 2008, 17:36
Hi,

Add to that you have same "patterns" written numerous times ... write them once and call them each time you need ...

each LCDOUT eats a lot of codespace ...

Alain

skimask
- 29th October 2008, 19:07
DT's gonna love this



DEFINE LCD_DREG PORTB 'Define PIC port used for LCD Data lines
DEFINE LCD_DBIT 4 'Define first pin of portb connected to LCD DB4
DEFINE LCD_RSREG PORTB 'Define PIC port used for RS line of LCD
DEFINE LCD_RSBIT 3 'Define Portb pin used for RS connection
DEFINE LCD_EREG PORTB 'Define PIC prot used for E line of LCD
DEFINE LCD_EBIT 0 'Define PortB pin used for E connection
DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
DEFINE LCD_LINES 2 'Define using a 2 line LCD
DEFINE LCD_COMMANDUS 2000 'Define delay between sending LCD commands
DEFINE LCD_DATAUS 50 'Define delay time between data sent.
CMCON=7 : CVRCON=0 : ButStart var Portc.0 : ButStop var Portc.1
ButReset var Portc.2 : Butup var portc.3 : Butdwn var portc.4
BannerOffset var BYTE : CounterA var BYTE : CounterB var BYTE
CounterC var BYTE : DataA var BYTE : Hours var BYTE
Hundredths var BYTE : Minutes var BYTE : OverflowError var BIT : RunningFlag var BIT
Seconds var BYTE : SetupTimeOut var WORD : TMR1Cal var BYTE : IHOURS VAR BYTE
IMINUTES VAR BYTE : TIMER VAR BYTE : TMR1CalAR var Byte : TMR1RunOn var WORD
Data @0,0 ' Advance/Retard Indicator
Data 0 ' Calibration Value
Data "Spec-ops.nl Tactical Game Aid - Enter Game Length"
TMR1CalMax con 100 : TMR1Preset con $D910 : TRISA=0 : TRISB=0 : TRISC=31
ADCON0=192 : ADCON1=7 : OPTION_REG.7=0 : RunningFlag=0 : Pause 1000
gosub clearlcd : BannerOffset=2 : Gosub DisplayBanner : Pause 2000
For CounterA=0 to 33 : BannerOffset=2+CounterA : Gosub DisplayBanner : Pause 350
Next CounterA : Pause 4000
MAINMENU: PAUSE 1000
MAINMENUA: gosub selectmenu : gosub setline2 : LCDOut "COUNTDOWN"
PAUSE 100 : IF BUTSTART=0 THEN MENUA
IF BUTUP=0 THEN MAINMENUB
GOTO MAINMENUA
MAINMENUB: gosub selectmenu : gosub setline2 : LCDOut " COUNT UP"
PAUSE 100 : IF BUTDWN=0 THEN MAINMENU
IF BUTSTART=0 THEN
TIMER=1 : PAUSE 20
IF BUTSTART=0 THEN
GOTO BEGINNING
ENDIF
ENDIF
PAUSE 50 : GOTO MAINMENUB
MenuA: PAUSE 1000 : TIMER=0
MENUCD: gosub clearlcd : LCDOUT " Preset 1" : gosub show30minutes : pause 100
IF BUTSTART=0 THEN preset1
IF BUTDWN=0 THEN CUSTOMA
IF BUTUP=0 THEN PRESET2
IF BUTRESET=0 THEN MAINMENU
GOTO MENUCD
CUSTOMA: PAUSE 1000
CUSTOMB: gosub clearlcd : LCDOUT "CUSTOM TIME" : gosub setline2
LCDOut "ENTER A CUSTOM TIME" : PAUSE 100
IF BUTSTART=0 THEN CUSTOM
IF BUTDWN=0 THEN PRESET2
IF BUTUP=0 THEN MENUCD
IF BUTRESET=0 THEN MAINMENU
PAUSE 50 : GOTO CUSTOMB
PRESET1: PAUSE 1000
PRESET1A: gosub acceptpreset1 : gosub show30minutes : PAUSE 100
IF BUTSTART=0 THEN PRESET1set
IF BUTRESET=0 THEN MENUCD
GOTO PRESET1A
PRESET1SET: IHOURS=0 : IMINUTES=30 : PAUSE 50 : GOTO CONTINUE
PRESET2: PAUSE 1000
PRESET2A: gosub clearlcd : LCDOUT " Preset 2" : gosub show45minutes
PAUSE 100
IF BUTSTART=0 THEN PRESET2A
IF BUTUP=0 THEN CUSTOMA
IF BUTDWN=0 THEN menuCD
IF BUTRESET=0 THEN MAINMENU
GOTO PRESET2A
PRESET2B: PAUSE 1000
PRESET2C: gosub acceptpreset2 : gosub show45minutes : PAUSE 100
IF BUTSTART=0 THEN PRESET2SET
IF BUTRESET=0 THEN MENUCD
GOTO PRESET2C
PRESET2SET: IHOURS=0 : IMINUTES=45 : PAUSE 50 : GOTO CONTINUE
CUSTOM: PAUSE 1000 : IHOURS=0 : IMINUTES=3
HOURSI: If Butup=0 then IHOURS=IHOURS+1
If BUTDWN=0 THEN IHOURS=IHOURS-1
IF BUTSTART=0 THEN MINSA
IF BUTRESET=0 THEN MENUA
pause 50 : GOSUB TIMESETUP : GOTO HOURSI
MINSA: PAUSE 1000
MINSI: IF BUTUP=0 THEN IMINUTES=IMINUTES+1
IF BUTDWN=0 THEN IMINUTES=IMINUTES-1
IF BUTRESET=0 THEN HOURSI
IF BUTSTART=0 THEN CONTINUE
PAUSE 50 : GOSUB TIMESETUP : GOTO MINSI
timesetup: pause 50 : gosub clearlcd : LCDOUT "GAME LENGTH" : gosub showhoursminutes : PAUSE 50 : REturn
Continue: gosub clearlcd : LCDOUT "Settings Saved" : gosub showhoursminutes
pause 6000
BEGINNING: Gosub SetTimer ' Set the Timer for next 10mS Interrupt
IF TIMER=1 THEN
On Interrupt goto TickCountUP
ELSE
On Interrupt goto TickCount
ENDIF
PIE1.0=1 : INTCON.6=1 : INTCON.7=1 ' Enable Global Interrupts
DisplayReset: gosub clearlcd : Read 0,TMR1CalAR : Read 1,TMR1Cal : Hundredths=0
Seconds=0 : Minutes=IMINUTES
Hours=IHOURS : OverflowError=0
Enable
DisplayLoop: If ButStart=0 then RunningFlag=1
If ButStop=0 then RunningFlag=0
LCDOut $FE,$80,DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds,".",DEC2 Hundredths
If OverflowError=1 then
If Seconds.0=1 then
LCDOut $FE,$8C,"ERR"
else
LCDOut $FE,$8C," "
endif
endif
If RunningFlag=1 then goto DisplayLoop
If ButReset=1 then goto DisplayLoop
Disable
ResetClock: LCDOut $FE,1,"Reset OK" : Pause 1000 : Seconds=1
While Seconds < 5
Pause 1000 : If ButReset=1 then goto DisplayReset
Seconds=Seconds+1
Wend
SetUpTimeout=0
Calibration: LCDOut $FE,1,"Calibrate: "
While ButReset=0:Wend ' Wait for User to release finger
CalibrationLoop: LCDOut $FE,$8B
If TMR1Cal=0 then
LCDOut " "
else
If TMR1CalAR=0 then
LCDOut "+"
else
LCDOut "-"
endif
endif
LCDOut #TMR1Cal," "
If TMR1CalAR=0 then
If ButStart=0 then Gosub CalAdvance
If ButStop=0 then Gosub CalRetard
else
If ButStart=0 then Gosub CalRetard
If ButStop=0 then Gosub CalAdvance
endif
If ButReset=0 then
Write 0,TMR1CalAR : PAUSE 10 : Write 1,TMR1Cal : PAUSE 10
LCDOut $FE,1,"Have a Nice Day" : Pause 1000
Goto DisplayReset
endif
SetupTimeout=SetupTimeout+1 : If SetupTimeout>200 then goto DisplayReset
Pause 100 : Goto CalibrationLoop
CalAdvance: SetupTimeout=0
If TMR1Cal=>TMR1CalMax then
TMR1Cal=TMR1cALmAX : TMR1CalAR=TMR1CalAR^1
else
TMR1Cal=TMR1Cal+1
endif
Return
CalRetard: SetupTimeout=0
If TMR1Cal=0 then
TMR1Cal=1 : TMR1CalAR=TMR1CalAR^1
else
TMR1Cal=TMR1Cal-1
endif
Return
DisplayBanner: CounterC=BannerOffset+15 : gosub setline1 : For CounterB=BannerOffset to CounterC
Read CounterB,DataA : LCDOut DataA : Next CounterB : Return
SetTimer: T1CON.0=0 : TMR1RunOn.Highbyte=TMR1H : TMR1RunOn.Lowbyte=TMR1L : TMR1RunOn=TMR1Preset+TMR1RunOn
If TMR1CalAR=0 then ' Calibration ADVANCE (add) or RETARD (subtract)
TMR1RunOn=TMR1RunOn+TMR1Cal
else
TMR1RunOn=TMR1RunOn-TMR1Cal
endif
TMR1H=TMR1RunOn.Highbyte : TMR1L=TMR1RunOn.Lowbyte : T1CON.0=1 : PIR1.0=0
Return
TickCount: Gosub SetTimer ' Set the Timer for next 10mS Interrupt
If RunningFlag=1 then ' If timing actually enabled... then...
IF HUNDREDTHS=0 THEN
IF SECONDS=0 THEN
IF MINUTES=0 THEN
IF HOURS=0 THEN
GOTO TIMEUP
ENDIF
ENDIF
ENDIF
ENDIF
If seconds=0 then
hundredths=0
else
Hundredths=Hundredths-1
If Hundredths=0 then
Hundredths=99 : seconds=seconds-1
endif
endif
If minutes>0 then
If Seconds=0 then
Seconds=59 : minutes=minutes-1
endif
endif
If hours>0 then
If Minutes=0 then
Minutes=59 : hours=hours-1
endif
endif
If Hours>99 then
Hours=0 : OverFlowError=1
endif
endif
Resume
timeup: gosub setline2 : LCDOUT "Time is up" : GOTO timeup
TickCountUP: Gosub SetTimer ' Set the Timer for next 10mS Interrupt
If RunningFlag=1 then ' If timing actually enabled... then...
Hundredths=Hundredths+1
If Hundredths>99 then
Hundredths=0
Seconds=Seconds+1
If Seconds>59 then
Seconds=0
Minutes=Minutes+1
If Minutes>59 then
Minutes=0
Hours=Hours+1
If Hours>99 then
Hours=0
OverFlowError=1
endif
endif
endif
endif
endif
Resume
clearlcd: lcdout $fe,1 : return
setline1: lcdout $fe,$80 : return
setline2: lcdout $fe,$c0 : return
selectmenu: gosub clearlcd : LCDOUT " SELECT MENU" : return
acceptpreset: gosub clearlcd : lcdout "Accept Preset ?" : return
acceptpreset1: gosub acceptpreset : lcdout $fe , $8e , "1" : return
acceptpreset2: gosub acceptpreset : lcdout $fe , $8e , "2" : return
show30minutes: gosub setline2 : lcdout "00:30:00.00" : return
show45minutes: gosub show30minutes : lcdout $fe , $c3 , "45" : return
showhoursminutes: LCDOut $FE,$C0,DEC2 IHours,":",DEC2 IMinutes,":00.00" : return
End

Just a small example of how some small changes can save some big space...

chrisshortys
- 29th October 2008, 22:43
Thanks for all the replies guys!


If you have a load of Text screen/Menus, you have few choices

1. using a bigger PIC
2. using an external EEPROM to store your Text
3. use the following method --- http://www.pbpgroup.com/modules/wfse...p?articleid=10

HTH

1. Could be somthing to try if all else fails. i have a number of p16f876A's sitting in my draw and would rather use them untill other routes have been used!
2. EEPROM? im guessing thats external memory? i havnt ventured anywhere near that yet! I'm still trying to learn the basics in programing before i move too far out!
3. I think i shall try having a closer look at this after work friday and see if i can make heads or tales of it!



When you say you ran out of memory, do you mean you ran out of code space or variable space?

When i went to assemble from basic to assm i got an error code along the lines of "fatal error: memory full


Hi,

Add to that you have same "patterns" written numerous times ... write them once and call them each time you need ...

each LCDOUT eats a lot of codespace ...

Alain

Sory once again my lack of understanding showing through!

Could you give me a small example i could see please?


Just a small example of how some small changes can save some big space...

So is it the blank lines that cause extra space to be used or is it the coding being on all seperate lines?

thanks again people!

skimask
- 29th October 2008, 22:47
2. EEPROM? im guessing thats external memory? i havnt ventured anywhere near that yet! I'm still trying to learn the basics in programing before i move too far out!
Read the 16F877A datasheet


When i went to assemble from basic to assm i got an error code along the lines of "fatal error: memory full
"along the lines of" kinda leave it open to interpretation...


Could you give me a small example i could see please?
Search...search...search...


So is it the blank lines that cause extra space to be used or is it the coding being on all seperate lines?
No, nothing to do with it. I hate vertically scrolling on the PC, so I pack it all in.

chrisshortys
- 10th November 2008, 13:17
Well i havnt been able to do any coding for a little while but i have been thinking of ways of altering my code.

I have a quick question now.

When you set up a piece of information in the coding say you use:

example var word

now i know you can do things like:

if butstart=0 then
example=8
end if

and you can send this to a LCD or use it for what ever you need.

Now my question is can you do the same for an actual word?
e.g.

if butstart=0 then
example=hello
end if

then when using the LCDOUT command have it refer to "example"?

sory if i havnt made this very clear but im struggling with try to explain what exactly i mean...

mister_e
- 10th November 2008, 16:23
From what I understand of your explanation... If hello is a variable or a constant, then yes it works.

Archangel
- 10th November 2008, 18:34
From what I understand of your explanation... If hello is a variable or a constant, then yes it works.
Hi Guys, I think he wants to call a string. In which case, you could put each letter in an array.

chrisshortys
- 10th November 2008, 18:43
This might make it a little clearer:


tempcode:

if butstart=0 then
text="start" <<<<<<<<<<<
endif

if butstop=0 then
text= "stop" <<<<<<<<<<<<<
endif

if butreset=0 then
text= "reset" <<<<<<<<<
endif

gosub lcdcontrol
goto tempcode


lcdcontrol:
LCDOUT $FE, 1, data <<<<<<<<<<<<<
pause 20
return

But im getting a error: Bad expression on the following lines marked above with a <<<<<

Archangel
- 10th November 2008, 18:46
That's because "start" is a 5 byte string and it will not fit in a byte or word variable. It will fit into a 5 byte array.

chrisshortys
- 10th November 2008, 18:48
ok well i had text deffined as a word so that will be why then!

So how do you use a 5 byte array?

Also the words that im currecntly using will be replaced and could be upo 16 characters long!

mister_e
- 10th November 2008, 18:55
There's always different thought for x problem, if it was me, i would use one of the next approach.

1. Store Text string in internal or external EEPROM, Text variable would return the start address of your text string. Your string should be terminated by a NULL (or 0), so when you call the Display routine, it just read from the eeprom, show it, go to next character and continue untill it reach the NULL (0).

2. Almost like the above, but storing text String in the codespace. Something around the following
http://www.pbpgroup.com/modules/wfsection/article.php?articleid=10 There's quite a few version of it on this forum.

chrisshortys
- 10th November 2008, 19:27
Thanks for that mister_e!

ok so i have the code as this now:


'************************************************* ***************
'* Name : STRINGS.PBP *
'* Author : Darrel Taylor / John Barrat *
'* Date : 5/30/2003 *
'* Note: Strings must be NULL Terminated *
'************************************************* ***************
DEFINE LOADER_USED 1 ' If using bootloader
DEFINE OSC 4
DEFINE HSER_TXSTA 24h ' Use this for Higher Baud Rates
DEFINE HSER_SPBRG 25 ' 9600 Baud at 4mhz
'
DEFINE LCD_DREG PORTB 'Define PIC port used for LCD Data lines
DEFINE LCD_DBIT 4 'Define first pin of portb connected to LCD DB4
DEFINE LCD_RSREG PORTB 'Define PIC port used for RS line of LCD
DEFINE LCD_RSBIT 3 'Define Portb pin used for RS connection
DEFINE LCD_EREG PORTB 'Define PIC prot used for E line of LCD
DEFINE LCD_EBIT 0 'Define PortB pin used for E connection
DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
DEFINE LCD_LINES 2 'Define using a 2 line LCD
DEFINE LCD_COMMANDUS 2000 'Define delay between sending LCD commands
DEFINE LCD_DATAUS 50 'Define delay time between data sent.

' Control Buttons/Lines
' ---------------------
ButStart var Portc.0 ' Take this pin low momentarily to START timing
ButStop var Portc.1 ' Take this pin low momentarily to STOP timing
ButReset var Portc.2 ' Take this pin low momentarily to RESET clock
Butup var portc.3 ' Take this pin low momentarily to increase clock time
Butdwn var portc.4 ' Take this pin low momentarily to decrease clock time


Addr var word
TwoChars var word
Char var byte

Clear

goto StartLoop ' Required

String1:
@ da "This is a string",0

AnotherString:
@ da "Here is another string",0

'------------GetAddress Macro - Location insensitive -------------------------
ASM
GetAddress macro Label, Wout ; Returns the Address of a Label as a Word
CHK?RP Wout
movlw low Label
movwf Wout
movlw High Label
movwf Wout + 1
endm
ENDASM


StartLoop ' This loop repeats continuously just as a test.
@ GetAddress _String1, _Addr ' Get address of String
gosub StringOut ' Send the String
hserout [13,10] ' New Line

@ GetAddress _AnotherString, _Addr ' Get address of String
gosub StringOut ' Send the String
hserout [13,10] ' New Line
pause 500
goto StartLoop ' Repeat


StringOut: ' Send the string out via Hserout
Readcode Addr, TwoChars ' Get the 14 bit packed characters
Char = TwoChars >> 7 ' Separate first char
if Char = 0 then StringDone ' Look for Null char, Stop if found
hserout [Char] ' Send first char
Char = TwoChars & $7F ' Separate second char
if Char = 0 then StringDone ' Look for Null char, Stop if found
hserout [Char] ' Send the second char
Addr = Addr + 1 ' Point to next two characters
goto StringOut ' Continue with rest of the string
StringDone:
return

end

If somone could point a way to a LCDOUT command to display one of the strings on there it would be greatly appreciated! As i have tried a few ways but due to my lack of understanding fail :p

mister_e
- 10th November 2008, 19:29
replacing HSEROUT with LCDOUT should work?

Which PIC you work with? The above is for 16F

chrisshortys
- 10th November 2008, 19:33
Im using the P16F876A

i tried


StartLoop ' This loop repeats continuously just as a test.
@ GetAddress _String1, _Addr ' Get address of String
gosub StringOut ' Send the String
LCDOUT $FE, 1, [13,10] ' New Line

@ GetAddress _AnotherString, _Addr ' Get address of String
gosub StringOut ' Send the String
LCDOUT $FE, 1, [13,10] ' New Line
pause 500
goto StartLoop ' Repeat


but this just gave me a bad expression

mister_e
- 10th November 2008, 19:40
you don't need those square brackets []
try something like...


Start
@ GetAddress _AnotherString, _Addr ' Get address of String
LCDOUT $FE,1 ' Here you place your LCD cusor where you want
gosub StringOut ' Send the String
pause 500
goto Start ' Repeat


StringOut: ' Send the string out via Hserout
Readcode Addr, TwoChars ' Get the 14 bit packed characters
Char = TwoChars >> 7 ' Separate first char
if Char = 0 then StringDone ' Look for Null char, Stop if found
LCDOUT Char ' Send first char
Char = TwoChars & $7F ' Separate second char
if Char = 0 then StringDone ' Look for Null char, Stop if found
LCDOUT Char ' Send the second char
Addr = Addr + 1 ' Point to next two characters
goto StringOut ' Continue with rest of the string
StringDone:
return

chrisshortys
- 10th November 2008, 19:43
ok thanks again!
I shall try that when i get in again tonight!

Archangel
- 10th November 2008, 21:25
Hi Chris, sorry for the delay, good old ATT DSL service is intermittant and they won't fix it. First of all, Mister_e is right, as usual, storing strings in eeprom is a good way to do it, I was only trying to explain why you're way would not work for you. You could in theory, create a byte array to hold all the letters of the alphabet and then display them as groups of individual letter variables, you could. Or you could make individual variables representing words like stop go start etc. Many roads to Valhalla.

chrisshortys
- 10th November 2008, 23:18
Hi Chris, sorry for the delay, good old ATT DSL service is intermittant and they won't fix it. First of all, Mister_e is right, as usual, storing strings in eeprom is a good way to do it, I was only trying to explain why you're way would not work for you. You could in theory, create a byte array to hold all the letters of the alphabet and then display them as groups of individual letter variables, you could. Or you could make individual variables representing words like stop go start etc. Many roads to Valhalla.

Well thanks alot for the reply! I know there is always many a way to do one job when it comes to coding and im hoping by the help on the forums i can get a much broader variation on the methods i use!
So yes any ideas are very welcome :)
Especially if they come with little snips of code which helps me to understand :p

mister_e i tried that code and yep all good thank you very much!
Tommorrow night i shall play around with it some more and try to get different things when different buttons are pushed etc!

Archangel
- 11th November 2008, 07:55
Well thanks alot for the reply! I know there is always many a way to do one job when it comes to coding and im hoping by the help on the forums i can get a much broader variation on the methods i use!
So yes any ideas are very welcome :)
Especially if they come with little snips of code which helps me to understand :p

mister_e i tried that code and yep all good thank you very much!
Tommorrow night i shall play around with it some more and try to get different things when different buttons are pushed etc!
OK Chris look this over:http://www.picbasic.co.uk/forum/showthread.php?t=8876

chrisshortys
- 12th November 2008, 19:54
Well i thougth i would try another approach and see if this is possible. I have tried to create a lookup table but I'm having problems with this. The code starts to work, when i press a button it goes to the table, it goes to the location and it then only displays the first character
Am i missing somthing or is this a dead end?



DEFINE LCD_DREG PORTB 'Define PIC port used for LCD Data lines
DEFINE LCD_DBIT 4 'Define first pin of portb connected to LCD DB4
DEFINE LCD_RSREG PORTB 'Define PIC port used for RS line of LCD
DEFINE LCD_RSBIT 3 'Define Portb pin used for RS connection
DEFINE LCD_EREG PORTB 'Define PIC prot used for E line of LCD
DEFINE LCD_EBIT 0 'Define PortB pin used for E connection
DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
DEFINE LCD_LINES 2 'Define using a 2 line LCD
DEFINE LCD_COMMANDUS 2000 'Define delay between sending LCD commands
DEFINE LCD_DATAUS 50 'Define delay time between data sent.

' Control Buttons/Lines
' ---------------------
ButStart var Portc.0 ' Take this pin low momentarily to START timing
ButStop var Portc.1 ' Take this pin low momentarily to STOP timing
ButReset var Portc.2 ' Take this pin low momentarily to RESET clock
Butup var portc.3 ' Take this pin low momentarily to increase clock time
Butdwn var portc.4 ' Take this pin low momentarily to decrease clock time

b0 var word
w0 var word


Start:

Lookup2 B0, ["hello", "help", "sory", "no"], W0

If ButStart=0 then
b0=0
endif
If butstop=0 then
b0=b0-1
endif
if butup=0 then
b0=b0+1
endif


GOSUB LCDDisplay

Goto start



LCDDisplay:
LCDOUT w0
pause 60
return

end