6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 11:56 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: LED Blink Sample
PostPosted: Sun Jul 13, 2014 2:23 am 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
With the Arduino, BS2, or Propeller chip the first thing I always do is get an LED blinking. From there it is usually a short trip to bit banging stepper motor control signals. So I finally got something working using ehBasic, an LED, and a 6522. The program below sets PB0 for output and toggles the LED on and off 16 times.

Code:
10 REM Toggle VIA2.PB0 LOW and HIGH
20 REM Set up common VIA2 constants
30 Via2PRB=$7f60
40 Via2DDRB=$7f62
50 FOR X = 0 TO 16
60 REM Set VIA2.PB0 as output
70 A = PEEK Via2DDRB
80 A = A AND $FE
90 POKE Via2DDRB, A
100 A = PEEK Via2PRB
110 A = A EOR $01
120 POKE Via2PRB, A
130 FOR Y = 1 TO 100
140 NEXT Y
150 NEXT X


Top
 Profile  
Reply with quote  
 Post subject: Re: LED Blink Sample
PostPosted: Sun Jul 13, 2014 7:45 am 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
In EhBASIC only the first 2 letters of variables are significant. So Via2PRB and Via2DDRB are the same variable: Vi. You are toggling the VIA's DDRB register instead of the PRB register, because that is the last definition of Vi. Of course that still works, if the LED is between Vcc and the port pin. PRB defaults to $00 after a reset. The port pin will start sinking current when it is defined as output and go to high-Z when it is not.

But you are not alone. I made the very same mistake in my first EhBASIC program.

edit: You will find more errors in your little program, if you fix the variables.

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
 Post subject: Re: LED Blink Sample
PostPosted: Sun Jul 13, 2014 2:13 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
Klaus2m5 wrote:
In EhBASIC only the first 2 letters of variables are significant. So Via2PRB and Via2DDRB are the same variable: Vi. You are toggling the VIA's DDRB register instead of the PRB register, because that is the last definition of Vi. Of course that still works, if the LED is between Vcc and the port pin. PRB defaults to $00 after a reset. The port pin will start sinking current when it is defined as output and go to high-Z when it is not.

But you are not alone. I made the very same mistake in my first EhBASIC program.

edit: You will find more errors in your little program, if you fix the variables.


Thanks for the feedback as that was exactly what I was looking for by posting this. I will fix that error and then find the others.

This is also an 80's flashback, that used to be common behavior among Pascal compilers, although I think it was six or eight characters that they considered significant. Used to drive me crazy.


Top
 Profile  
Reply with quote  
 Post subject: Re: LED Blink Sample
PostPosted: Sun Jul 13, 2014 5:16 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
After discovering the BITSET and BITCLR commands this got much easier.

Code:
10 REM Set up common VIA2 constants
20 PB=$7f60
30 DB=$7f62
40 REM Set VIA2.PB0 as output
50 BITSET DB,0
60 FOR X = 0 TO 16
70 BITSET PB,0
80 GOSUB 200
90 BITCLR PB,0
100 GOSUB 200
110 NEXT X
120 END
200 REM Delay loop
210 FOR Y=1 TO 50
220 NEXT Y
230 RETURN


I probably need a better way to wait than a delay loop. I've heard that 6522's have a one shot timer, so I'll need to see if that can help.


Top
 Profile  
Reply with quote  
 Post subject: Re: LED Blink Sample
PostPosted: Sun Jul 13, 2014 7:45 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8545
Location: Southern California
Martin_H wrote:
I probably need a better way to wait than a delay loop. I've heard that 6522's have a one shot timer, so I'll need to see if that can help.

The 6522 has two timers with several operating modes, but by themselves they might not give as much delay as you want. The methods in my article at http://wilsonminesco.com/multitask/index.html on Simple methods for multitasking without a multitasking OS, for systems that lack the resources to implement a multitasking OS, or where hard realtime requirements would rule one out anyway, can be implemented even in a simple BASIC system. Then you can do other useful things while delaying, instead of wasting that processor time in a delay loop. The delays will be pretty accurate regardless of other things you have going at the same time.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: