Author Topic: 8052-Basic Programing  (Read 7372 times)

Sheldon

  • Member
  • ***
  • Posts: 3
8052-Basic Programing
« on: December 27, 2010, 11:21:24 pm »

Hello everyone.

My name is Sheldon and I am new to this group.
 I have some 8052 Basic programing questions that I hope someone
 can help me with.

 I've constructed an 8052-Basic s.b.c. using circuits from Jan Axelson's
 Micro Ideabook. I've added 2 8255s for I.O. One 8255 is dedicated to an
 lcd display.

 The board and display work.
 
 I'd like to send variables to  the lcd and am wondering if it can be done in
 8052-Basic .

I can send strings to the lcd ok. Such as,

10  STRING 100,20
20  $(1)="TEMPERATURE IS"
30  FOR X =1 TO 14
40  D=ASC($(1),X) :GOSUB 100
50  NEXT X
90  END

100  XBY(X)=RS+1  Rem Bring register select lcd pin high
110  XBY(X)=RW     Rem Bring r/w select pin low to write
120  XBY(A)=D       Rem Write data to lcd
130  XBY(X)=E+1 :XBY(X)=3DE   Rem Toggle lcd e pin.
140  Return

 The subroutine is from the book too. Thanks Jan !

This works . However, if I want to send a variable such as,

10  2+2=N

I put it in the asc grinder as,

20  D=ASC(N) :GOSUB 100

Doesn't work. It sends N to the lcd.
I want to send the variable 4 to the lcd

 However,
10  PRINT N   Prints 4 to the monitor. And,

20  PRINT ASC(N)  Prints 70 to the monitor (asci of 4)

I've also tried putting the variable in a string like

10  $(2)=N
20  D=ASC(N) :GOSUB 100

Doesn't work.
Basic gives error for line 10.

Any ideas ?






Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 2596
    • Lakeview Research
Re: 8052-Basic Programing
« Reply #1 on: December 28, 2010, 06:12:25 pm »
If the value is between 0 and 9 try sending:

N + 48

(Don't use a string, just send the ASCII code.)

If the value is multiple digits, you'll need to extract each digit and send its value + 48:

D1 = INT(N/10) + 48
D2 = N - D1*10 + 48

This is off the top of my head. No guarantee.

Jan

Sheldon

  • Member
  • ***
  • Posts: 3
Re: 8052-Basic Programing
« Reply #2 on: December 29, 2010, 01:07:41 am »
         Jan,
  Thanks. I'll try the code and report the results.
  Sheldon

Sheldon

  • Member
  • ***
  • Posts: 3
Re: 8052-Basic Programing
« Reply #3 on: March 07, 2011, 02:15:18 am »
Jan,
Took your ideas,with some modifications to display 3 characters
on an lcd and came up with this working "code".
Since I didn't know how to make one subroutine send all the
characters,I rewrote it for each one.
Thanks.

My next project will use the 8052 Basic clock program from
the Idea Book and modify it for lcd display.
Sheldon.

REM SEND T (VARIABLE)  TO LCD
 435  N=T
  440 D1=INT(N/100)  :GOSUB 1500
  450 ST2=INT(N-D1*100)
  460 D2=INT(ST2/10) :GOSUB 1505
  470 D3=ST2-D2*10  :GOSUB 1510

REM SEND 1'ST CHARACTER TO LCD  (D1)
  1500 XBY(X)=RS+1
  1501 XBY (X)= RW
  1502 XBY(A)=D1+48
  1503 XBY (X)=E+1 :XBY(X)=E
  1504 RETURN

REM  SEND 2'ND CARACTER  (D2)
  1505 XBY(X)=RS+1
  1506 XBY (X)= RW
  1507 XBY(A)=D2+48
  1508 XBY (X)=E+1 :XBY(X)=E
  1509 RETURN

REM SEND 3'RD CARACTER  (D3)
  1510 XBY(X)=RS+1
  1511 XBY (X)= RW
  1512 XBY(A)=D3+48
  1513 XBY (X)=E+1 :XBY(X)=E
  1514 RETURN



Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 2596
    • Lakeview Research
Re: 8052-Basic Programing
« Reply #4 on: March 07, 2011, 10:31:29 am »
I'm glad to hear you got it working!

Jan