Programming with assembler and Motorola HC08

Ok, I’m programming something for a project of the University.

We have to show data through a LCD screen. The problem is that Port A is occupied with the Keyboard, and Port B, and some of Port C is occupied with LCD Data and LCD control.

What I wanted to do is to change Port B to input in the middle of the program, and then change it to output again, but it didn’t semm to work.

I have a MC68HC908GP32.

I asked to motorola, but they seem to ignore me. I just hope someone around here knows about this.

It should be seem.
I’m sorry about the double post, but I think I didn’t make a question.

Is it possible to change the status of a port? (from input to output or viceversa)

Well, in all honesty, this is a fairly obscure question, and that is likely why no one has responded. I have some experience with programming microcontrollers (Allen Bradley SLC/PLC, Parallax SX, GE Fanuc), and even I’ve never seen code for your type. I even tried a Google search to find help, thinking that there might be an online manual or something.

There are microcontrollers that do not let you change them from Input to Output and back after they startup. What sort of tools do you have available? Any reference docs online? Technical and I/O guides online? Parallax, for example, has all of their stuff downloadable from their website.

Here’s the datasheet:

[sub]warning: 410 page .pdf[/sub]
http://rocky.digikey.com/WebLib/Motorola/Web%20Data/MC68HC908GP32.pdf

After a quick look, I think it should be possible, but it’s been a long time since I’ve actually done any of this.

That data sheet indicates what to do: section 16.4.2.

Thanks for the datasheet, I have it already, but unless I’m mistaken, or there is an update from my datasheet, the problem is still not solved there.

Well, this are some things it might help me:

  1. I’m using ICS08GPGTZ In Circuit Simulator. (WinIDE)
  2. This is a piece of my program:

Init_PORT:
mov #$F0,DDRA ;Keyboard
mov #$FF,DDRB ;LCD Data
rts

That is the part when i inicialize the ports. (#$FF means Port B is an output)

But later in the program I try to define Port B as an input. I tried 2 different ways and got this:

           mov     #$FF,DDRB

This way, when I run the simulation, Port B changes its status as uninitialized.
The other way I tried it was bit by bit:

           bclr     0,DDRB
           bclr     1,DDRB
           bclr     2,DDRB
           bclr     3,DDRB
           bclr     4,DDRB
           bclr     5,DDRB
           bclr     6,DDRB
           bclr     7,DDRB

All went great until I cleared bit 7, when the simulation said the same thing (port B uninitialized).
I also tried to clear the port after the bit changing of the DDRB, but it didn’t help.

Have you tried using the reset instead of writing to the data direction registers?

How do I reset the DDRB?

Trying setting the status of port B after it becomes uninitiated.

I tried this:

mov #$FF,DDRB
clr portb
[font]
There’s no problem in that, but I tried this…
[/font=courier new]
mov #$FF,DDRB
mov #$00,DDRB
clr portb

… And the port cannot be initiated.

:smack: It should be “mov #$0,DDRB”

I don’t know how to reset it… I don’t have your simulator. I doubt that’s the issue, I just see that it does, in fact, have a reset.

Looking at the data sheet further, is there some problem with not setting the ADC Channel Select Bits to 1, thus turning off the ADC function, since Port B is a general purpose I/O and not just a digital one?

I think that the reset it refers to is the external reset of the chip (it is on pin #6), and when the reset is activated, those bits turn 0.

I don’t think that there is a problem with the ADC, because I’m just not using that function.

From this manual for you simulator , did you try using the “DDRB 00” command to reset port b to input mode?

BTW, how are your friends in class with you doing this?

-lv (who wouldn’t presume to post this unless I knew you were grasping for straws, as I knew nothing about this microprocessor before opening the link.)

My classmates weren’t using the port as an output and input. They were using a space of memory in the RAM to store the data you want to show in the LCD screen, and refresh the screen with this data every certain amount of time. this way they only needed port b as an output. So if they want to use what is written on the screen, they just have to read from the space of memory where it is stored.

I didn’t want to do this, because I will have to change a lot of my previous programming to adapt to that. Instead, I wanted to read from port b, and store that in the RAM.

Thanks for answering LordVor. I have to do some testing with this to see if that is the problem, because when I run the program (in real life), The program seems to change from output to input, and then to output (as I want it), but when I want to show what is stored in the RAM, it doesn’t show what it should.

Maybe it is not even changing the status of the port, or maybe I wrote the reading from LCD routine wrong (which I doubt ;))

I also noticed that that command (DDRB) is for the simulator, and I think that I cannot use it in the WinIDE (assembler) as a command.

Hm, what is portb?

Anyway, is it possible just to clear DDRB? Would that work?

portb = port b… I missed a space (I’m having too much of programming time)

And clearing DDRB doesn’t seem to work.

oops… The only place I wrote portb was in a code actually, so I didn’t missed a space.