Simple Program Hello does not run

General discussion on mikroBasic for AVR.
Post Reply
Author
Message
channelwood
Posts: 7
Joined: 27 Aug 2006 13:16
Location: Zürich, Switzerland

Simple Program Hello does not run

#1 Post by channelwood » 27 Aug 2006 13:51

Why doesn't this program run?
(mikroBasic 3.0 Demoversion for AT90S8515)

Code: Select all

program Hello

main:

   USART1_Init(9600)
   USART1_Write_Text("Hello World")

end.
Error:
E-3 'USART1_Init' was not declared

vanja
mikroElektronika team
Posts: 253
Joined: 27 Jan 2005 15:13
Contact:

#2 Post by vanja » 28 Aug 2006 08:23

Usart Hardware in new mega chips is different from mature AT90Sxxxx,
So libraries do not work for old ones.

Here is a source in Pascal for new one:

Code: Select all

//
//         ***     ****       ****   ********         v3.00
//       *******    ****     ****    *********
//      ***   ***    ****   ****     ***   ****
//      *********     **** ****      *********
//      *********      *******       *********
//      ***   ***       *****        ***    ***
//      ***   ***        ***         ***     ***
//

unit USART1;

uses uart_consts;

implementation

procedure Usart1_Init(baud_rate : longint);
var tmp: longint;
begin
  tmp   := Clock_kHz_ * 1000;
  tmp   := tmp div baud_rate;
  tmp   := tmp shr 4;
  dec(tmp);
  UBRRL := lo(tmp);
  UBRRH := hi(tmp);
  UCSRB := $18;
  UCSRC := $86;
end;

procedure Usart1_Init_Advanced(bps: longint; parity, data_bits, stop_bits: byte);
var loc : byte;
begin
  Usart1_Init(bps);
  loc := $80 or parity or stop_bits;
  UCSRC := loc or (data_bits and $0F);
  UCSRB := UCSRB or (data_bits and $F0);
end;

procedure Usart1_Write_Char(data: byte);
begin
  while (UCSRA and $20)=0 do nop;
  UDR:=data;
end;

function Usart1_Data_Ready : byte;
begin
  result:= UCSRA and $80;
  if result<>0 then result:=255;
end;

function Usart1_Read : byte;
begin
  result:=UDR;
end;

procedure Usart1_Write_Text(var uart_text: string[20]);
var i, data: byte;
begin
  i := 0;
  data := uart_text[0];
  while data <> 0 do
    begin
       Usart1_Write_Char(data);
       inc(i);
       data := uart_text[i];
    end;
end;

end.


You can try to make it work for old chips, just remember to change a name of procedures, for example add "_old" in name like : usart1_init_old.

I think that you have to change only name of the registers.

channelwood
Posts: 7
Joined: 27 Aug 2006 13:16
Location: Zürich, Switzerland

#3 Post by channelwood » 07 Sep 2006 10:22

No problem, it's not a project only a mikroBasic test.

I take another CPU and I get another error message.

Same program now with ATMEGA88

0:42, E-1, Error in ASM code: Register is out of range "293@102 UDR0 R0" :(

vanja
mikroElektronika team
Posts: 253
Joined: 27 Jan 2005 15:13
Contact:

#4 Post by vanja » 08 Sep 2006 08:07

Every chip has a definition files in defs folder, as you can see in file ATmega88def.abas, all include files for that chip, and there is a line:

Code: Select all

include "usart1A"
So, I gave you wrong file source, here is right one:

Code: Select all


module usart1A

include "uart_consts.abas"

implements

sub procedure Usart1_Init(dim baud_rate as longint)
dim tmp as longint
  tmp   = Clock_kHz_ * 1000
  tmp   = tmp div baud_rate
  tmp   = tmp >> 4
  dec(tmp)
  UBRR0L = tmp
  UBRR0H = longint(tmp >> 8)
  UCSR0B = $18
  UCSR0C = $86
end sub

sub procedure Usart1_Init_Advanced(dim bps as longint, dim parity, data_bits, stop_bits as byte)
dim loc_ as byte
  Usart1_Init(bps)
  loc_   = $80 or parity or stop_bits
  UCSR0C = loc_ or (data_bits and $0F)
  UCSR0B = UCSR0B or (data_bits and $F0)
end sub

sub procedure Usart1_Write_Char(dim data as byte)
  while (UCSR0A and $20)=0
    nop
  wend
  UDR0=data
end sub

sub function Usart1_Data_Ready as byte
  result= UCSR0A and $80
  if result<>0 then
  result=255
  end if
end sub

sub function Usart1_Read as byte
  result=UDR0
end sub

sub procedure Usart1_Write_Text(dim byref uart_text as string[20])
dim i, data as byte
  i = 0
  data = uart_text[0]
  while data <> 0
    Usart1_Write_Char(data)
    inc(i)
    data = uart_text[i]
  wend
end sub

end.
We will fix this up, and in new release you will get all usart libraries to work for all chips. Sorry for inconvenient.

channelwood
Posts: 7
Joined: 27 Aug 2006 13:16
Location: Zürich, Switzerland

#5 Post by channelwood » 11 Sep 2006 10:27

It does not run.
Obviously I don't understand what I have to do with the file usart1a.abas.

I renamed the old usart1a.mcl in the folder uses.
My program and usart1a.abas are saved and open, my program is in front.
I press Ctrl-F9 (Build) and get this errors:

Image
- Why I can't copy (Ctrl-C) text from the error-message window?

- Into which folder does the file usart1a.abas has to be? ?
- What means this errors?
- Why have I a syntax error in usart1a.abas?
- Why does the compiler found some errors in usart1a.abas and than he can't found the same file in atmega88def.abas?
- Are there something wrong with the paths?

channelwood
Posts: 7
Joined: 27 Aug 2006 13:16
Location: Zürich, Switzerland

#6 Post by channelwood » 11 Sep 2006 12:02

I have a additional serious problem with handling projects. :(

- I close the current project for writing another test program. (Close Project)
- I create a new project TEST2
- I write a very small program WITHOUT usart functions and press "Build".
- mikroBasic opens the file usart.abas and reports some errors.
Why and how can I exclude old files in a new project?

and

B.
- When I create a new project with the same name, mikroBasic opens the old file instead of an empty file. Why?
mikroBasic ask "Do you want the rewrite it?" Is this a write error?

C.
- With "Save Project As…" I make a copy of my project TEST2 with the new name TEST3.
- Old name is TEST2.abp
- New name ist TEST3.app and therefore is not shown in the open dialog box.
Does mikroBasic appends a wrong extention .app?

Oh, oh, - I see the mistake, it's again a remnant from the BASIC's ancestor PASCAL.

The default filetype in mikroBasic is mikroPascal Project (*.app) !

vanja
mikroElektronika team
Posts: 253
Joined: 27 Jan 2005 15:13
Contact:

#7 Post by vanja » 11 Sep 2006 12:51

We expecting release very soon.

B. It's suppose to be like that

C. We fix this problem

Thank you

woodfold
Posts: 9
Joined: 25 Jul 2008 02:35
Location: Greenville, NC

#8 Post by woodfold » 05 Aug 2008 20:02

So what is supposed to be done with this? You never answered.

And are usart libs working with atmega162 now?

Post Reply

Return to “mikroBasic for AVR General”