This question is not about whether my assembly code is correct or not. It is about how to include it in my code. I'm getting about a bazillion errors. I think I'm doing something fundamentally wrong, even though the HELP makes is sound easy:
You can use microcontroller assembler code within your Great Cow BASIC code.
You can put the assembler code inline in with your source code. The assembler code will be passed through to the assembly file associated with your project.
Great Cow BASIC should recognise all of the commands in the microcontroller datasheet.
The commands should be in lower case, this is good practice, and have a space or tab in front of the command.
Here's a partial listing of the code. It begins with GCB commands:
SubQuit()GLCDCLSGLCDPrint0,0,"GOODBYE"GLCDPrint(0,16,"GEA 2017")GLCDDrawString0,32,"drawString"Line(3,3,127,3)Line(3,9,127,9)Wait5sGLCDCLS'This puts atmega328p in power-down mode'Ayoutubevideoshowsconsumptionof17.xmAreducedto0.3xuA' https://youtu.be/urLSDi7SD8M'1)Pullalltheunusedpinseitherhighorlow' leave a pin high if you want to wake it up with a button push'2)TurnyourLCDoff(SSD1306)'3) Turn off the ADC (Analog Digital Converter); bit 7 ADCSRA --> 1'4)SetSMCR(SleepModeControlRegister);bits3,2,1SMCR-->0,1,0'5) Set SMCR Sleep Mode Enable bit; bit 0 SMCR --> 1'6)DisableBrownOutDetectionduringsleep.It's a procedure'6a)Bits6and5setto1;bits6,5-->1' 6b) WITHIN 4 CLOCK CYCLES: bit 6 --> 1, bit 5 --> 0'6c)WITHIN3CLOCKCYCLES:EnableSleepMode(alreadydoneinstep5)'7) Put it to sleep; sleep'8)buttonpushwillwakeitup,anditwillresumewhereitleftoff.'1) Pull ports low. Comment out whatever you don'tneed'PORT B DIGITAL ;DIR PORTB.0 OUT 'D8mywakeupbuttonishereDIRPORTB.1OUT'D8 DIR PORTB.2 OUT 'D10DIRPORTB.3OUT'D11 DIR PORTB.4 OUT 'D12DIRPORTB.5OUT'D13 'PORTCANALOGDIRPORTC.0OUT'A0 DIR PORTC.1 OUT 'A1DIRPORTC.2OUT'A2 DIR PORTC.3 OUT 'A3;DIRPORTC.4OUT'A4 - I2C SDA ;DIR PORTC.5 OUT 'A5-I2CSCL' PORT D DIGITAL DIR PORTD.0 OUT 'RX0DIRPORTD.1OUT'TX1 DIR PORTD.2 OUT 'D2DIRPORTD.3OUT'D3 DIR PORTD.4 OUT 'D4DIRPORTD.5OUT'D5 DIR PORTD.6 OUT 'D6DIRPORTD.7OUT'D7'2)Turnofflcd(SSD1306)Write_Command_SSD1306(SSD1306_DISPLAYOFF)'3) Turn off ADCSRA. Have to turn it back on manually adcsra &= ~(1 << 7)'4)SetSMCRsmcr=0x00;smcr|=(1<<2)...andsoon
The first few errors reported:
Great Cow BASIC (0.98.01 2017-10-27)
21.4 Sec. <<< WARNINGs / ERRORs while compiling!
Doubleclick on errormessage below to go to sourcecode-line:
Nashville Number Machine.gcb (758): Error: Invalid variable name: ADCSRA&
Nashville Number Machine.gcb (758): Error: Variable ADCSRA& was not explicitly declared
Nashville Number Machine.gcb (758): Error: Invalid variable name: <7
Nashville Number Machine.gcb (758): Error: Variable <7 was not explicitly declared
Nashville Number Machine.gcb (758): Error: Missing operand, before <>
Nashville Number Machine.gcb (763): Error: Invalid variable name: SMCR|
Nashville Number Machine.gcb (763): Error: Variable SMCR| was not explicitly declared
Nashville Number Machine.gcb (763): Error: Invalid variable name: <2
Nashville Number Machine.gcb (763): Error: Variable <2 was not explicitly declared
The compiler does not seem to recognize that I'm trying to include assembly code. adcsra is a command, not a variable. The same is pretty much true for every other error reported, but not included here. The way I read the HELP is that there doesn't need to be an indicator that means THE FOLLOWING IS ASSEMBLY CODE and yet, that's what these errors imply the code needs.
Whatever assembly code I've found on the forum is for PICs, and so maybe this is somehow different. Can someone give me a push in the right direction?
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
George,
You are making this too difficult. i don't recognize this language and maybe I have been away from assembler too long. just use the GCB.
item 3 turn off adc. look it up in the data sheet and the bit is called ADEN. You are right it is bit 7 of the adcsra register.
code is as simple as ADEN = 0
item 4 SMCR sleep bits are SM0 , SM1 , SM2
can it be as simple as
SM0 = 0
SM1 =1
SM2= 0
The Mega328p dat file used by GCB names all the registers and Bits of registers so you can use them is your code.
Good Luck
Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Mike, you're totally right! (in theory, at this point, but it looks very promising) My code comments are newly annotated, and I'll change my MACRO code to GCB commands and see how it goes.
Thanks for the tip.
'3) Turn off the ADC (Analog Digital Converter); bit 7 ADCSRA --> 1 'GCB:ADEN=0'4) Set SMCR (Sleep Mode Control Register); bits 3,2,1 SMCR --> 0,1,0 'GCB:SM2=0,SM1=1,SM0=0'5) Set SMCR Sleep Mode Enable bit; bit 0 SMCR --> 1 'GCB:SE=1'6) Disable Brown Out Detection during sleep. It'saprocedure' 6a) Bits 6 and 5 set to 1; bits 6,5 --> 1 'GCB:BODS=1,BODSE=1' 6b) WITHIN 4 CLOCK CYCLES: bit 6 --> 1, bit 5 --> 0 'GCB:BODS=1,BODSE=0
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Those are the commands in the data sheet. They are also the commands the guy uses in youtube video, except he does it in C. It doesn't matter to me what I use, as long as I can accomplish the task.
I think that the Help Text should rather read Mnemonics rather than commands.
It recognises the Instruction set but not the Macro Commands.
adcsra &= ~(1 << 7)
is a macro but in GCBASIC you could say:
adcsra = adcsra AND FnLSL(1, 7)
and smcr |= (1 << 2) would be:
smcr = smcr OR FnLSL(1, 2)
Cheers
Chris
Last edit: Chris Roper 2017-12-13
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm running Windows 7 Home, SP1
This question is not about whether my assembly code is correct or not. It is about how to include it in my code. I'm getting about a bazillion errors. I think I'm doing something fundamentally wrong, even though the HELP makes is sound easy:
Here's a partial listing of the code. It begins with GCB commands:
The first few errors reported:
The compiler does not seem to recognize that I'm trying to include assembly code. adcsra is a command, not a variable. The same is pretty much true for every other error reported, but not included here. The way I read the HELP is that there doesn't need to be an indicator that means THE FOLLOWING IS ASSEMBLY CODE and yet, that's what these errors imply the code needs.
Whatever assembly code I've found on the forum is for PICs, and so maybe this is somehow different. Can someone give me a push in the right direction?
Thanks
George,
You are making this too difficult. i don't recognize this language and maybe I have been away from assembler too long. just use the GCB.
item 3 turn off adc. look it up in the data sheet and the bit is called ADEN. You are right it is bit 7 of the adcsra register.
code is as simple as ADEN = 0
item 4 SMCR sleep bits are SM0 , SM1 , SM2
can it be as simple as
SM0 = 0
SM1 =1
SM2= 0
The Mega328p dat file used by GCB names all the registers and Bits of registers so you can use them is your code.
Good Luck
Mike
Mike, you're totally right! (in theory, at this point, but it looks very promising) My code comments are newly annotated, and I'll change my MACRO code to GCB commands and see how it goes.
Thanks for the tip.
I think that the Help Text should rather read Mnemonics rather than commands.
It recognises the Instruction set but not the Macro Commands.
adcsra &= ~(1 << 7)
is a macro but in GCBASIC you could say:
adcsra = adcsra AND FnLSL(1, 7)
and smcr |= (1 << 2) would be:
smcr = smcr OR FnLSL(1, 2)
Cheers
Chris
Last edit: Chris Roper 2017-12-13
Chris!
First, thanks for the information. I didn't know.
Second, how did you both quote AND overwrite my post?
Mike, in case you didn't see it, I did thank you for the tip. I'll try it.