Menu

Including assembly code in my GCB program

Help
2017-12-13
2017-12-14
  • George Alvarez

    George Alvarez - 2017-12-13

    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:

    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:

    Sub Quit()
    
       GLCDCLS
       GLCDPrint 0, 0, "GOODBYE"
       GLCDPrint (0, 16, "GEA 2017")
       GLCDDrawString 0,32,"drawString"
       Line (3,3,127,3)
       Line (3,9,127,9)
       Wait 5 s
       GLCDCLS
    
    'This puts atmega328p in power-down mode
    'A youtube video shows consumption of 17.x mA reduced to 0.3x uA
    ' https://youtu.be/urLSDi7SD8M
    
    '1) Pull all the unused pins either high or low
    '   leave a pin high if you want to wake it up with a button push
    '2) Turn your LCD off  (SSD1306)
    '3) Turn off the ADC (Analog Digital Converter); bit 7 ADCSRA --> 1
    '4) Set SMCR (Sleep Mode Control Register); bits 3,2,1 SMCR  --> 0,1,0
    '5) Set SMCR Sleep Mode Enable bit; bit 0 SMCR  --> 1
    '6) Disable Brown Out Detection during sleep.  It's a procedure
    ' 6a) Bits 6 and 5 set to 1; bits 6,5 --> 1
    ' 6b) WITHIN 4 CLOCK CYCLES: bit 6 --> 1, bit 5 --> 0
    ' 6c) WITHIN 3 CLOCK CYCLES: Enable Sleep Mode (already done in step 5)
    '7) Put it to sleep; sleep
    '8) button push will wake it up, and it will resume where it left off.
    
    '1) Pull ports low. Comment out whatever you don't need
    
        'PORT B DIGITAL
        ;DIR PORTB.0 OUT  'D8   my wake up button is here
        DIR PORTB.1 OUT   'D8
        DIR PORTB.2 OUT   'D10
        DIR PORTB.3 OUT   'D11
        DIR PORTB.4 OUT   'D12
        DIR PORTB.5 OUT   'D13
    
        'PORT C ANALOG
        DIR PORTC.0 OUT  'A0
        DIR PORTC.1 OUT  'A1
        DIR PORTC.2 OUT  'A2
        DIR PORTC.3 OUT  'A3
        ;DIR PORTC.4 OUT  'A4 - I2C SDA
        ;DIR PORTC.5 OUT  'A5 - I2C SCL
    
       ' PORT D DIGITAL
        DIR PORTD.0 OUT  'RX0
        DIR PORTD.1 OUT  'TX1
        DIR PORTD.2 OUT  'D2
        DIR PORTD.3 OUT  'D3
        DIR PORTD.4 OUT  'D4
        DIR PORTD.5 OUT  'D5
        DIR PORTD.6 OUT  'D6
        DIR PORTD.7 OUT  'D7
    
    '2) Turn off lcd (SSD1306)
    
        Write_Command_SSD1306(SSD1306_DISPLAYOFF)
    
    '3) Turn off ADCSRA.  Have to turn it back on manually
    
        adcsra &= ~(1 << 7)
    
    '4) Set SMCR
    
        smcr = 0x00;
        smcr |= (1 << 2)
    
        ... and so on
    

    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

     
  • mmotte

    mmotte - 2017-12-13

    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

     
    • George Alvarez

      George Alvarez - 2017-12-14

      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's a procedure
      ' 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
      
       
  • George Alvarez

    George Alvarez - 2017-12-13

    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
  • George Alvarez

    George Alvarez - 2017-12-14

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.