![]() |
Forum Index : Microcontroller and PC projects : library trouble
Author | Message | ||||
drkl![]() Senior Member ![]() Joined: 18/10/2015 Location: HungaryPosts: 102 |
Hi, What is the mistake? I put it in library SUB MM.STARTUP 'LCD: CONST D4=38,D5=37,D6=36,D7=35,RS=12,EN=13,CHLCD=2 LCD INIT D4,D5,D6,D7,RS,EN DIM C1$,C2$ END SUB SUB KIIR IF CHLCD=0 OR CHLCD=2 THEN PRINT CHR$(13);" "; PRINT CHR$(13);C1$;" ";C2$; LCD 1,C16,C1$: LCD 2,C16,C2$ ELSE LCD 1,C16,C1$: LCD 2,C16,C2$ ENDIF END SUB library save, press reset the simple main program, download,run C1$="ALMA" C2$="KORTE" KIIR END the message: ALMA KORTE [LIBRARY] LCD 1,C16,C1$: LCD 2,C16,C2$ Error: Not open > Wihout library (put subroutins in main program) it operates... If anybody help me... drk |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3303 |
The Subroutine MM.STARTUP is run when the Micromite first powers up. So it is useful for things like printing a message or loading TFT LCD drivers as PeterM does. It is NOT good for general setup of MMBasic (like dimensioning arrays, the LCD INIT command, etc). The reason is that when you type RUN MMBasic clears everything ready for a fresh start. This includes closing comms (serial I2C, etc), clearing all variables, resetting I/O pins to not configured, etc. This is done so that every program starts with a "clean slate", ie, everything is the same every time you run a program. So, in your MM.STARTUP subroutine you setup the LCD but it was closed again when you typed RUN. I don't know why you would want to setup the LCD in a library but if you do want to do that you should not put the initialisation code in a subroutine but just leave it as a normal program but in the library. This is because, when you type RUN, MMBasic will clear everything then run the code in the library before it runs the program in main memory. So, your library should look something like this: CONST D4=38,D5=37,D6=36,D7=35,RS=12,EN=13,CHLCD=2
LCD INIT D4,D5,D6,D7,RS,EN DIM C1$,C2$ SUB KIIR IF CHLCD=0 OR CHLCD=2 THEN PRINT CHR$(13);" "; PRINT CHR$(13);C1$;" ";C2$; LCD 1,C16,C1$: LCD 2,C16,C2$ ELSE LCD 1,C16,C1$: LCD 2,C16,C2$ ENDIF END SUB The first three lines will be run immediately before the program in main memory is run (because they are not in a sub). This is mentioned (very briefly) on page 59 of the manual - I will give it more prominence in the next version of the manual. As a side benefit the constants that you defined will now be seen throughout your program. This is because constants defined inside a subroutine are only visible inside that subroutine. Geoff Geoff Graham - http://geoffg.net |
||||
paceman Guru ![]() Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
That's a really good explanation Geoff. I haven't used LIBRARY or STARTUP yet but I was pretty vague on how it worked. When you do edit the Manual I reckon you could drop that explanation in pretty much just as it is (different code maybe :) Greg |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |