News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

ASM I/O on an HCS12 micro controller

Started by kayduhbk, April 09, 2013, 11:50:53 AM

Previous topic - Next topic

kayduhbk

Iam using the HCS12 micro controller. The following program that I have takes the input from an on board keypad and displays letters to an on board LCD depending on which key is pressed (I only attached the portion of the code dealing with the inputs / outputs, i can attach the rest if need be but its easier on the eyes this way).

What I would like to do is to get rid of the keypad being used as the inputs, and use a sensor that I have which sends active low signals though 3 separate pins instead. That way in stead of having to push the keypad each time, whenever the sensor reads one of the readings (either PortA1, 2 or 3) it will display the correct letter.

The init_keypad function sets PortA0-PortA3 as inputs.

In the getkey function im not sure how to change the if statements to read PortA0-PortA3 individualy


void init_keypad(void){
    DDRA = 0xf0;  // PA7-PA4 output; PA3-PA0 input
    DDRB = 0xf0;
    PUCR |= 1;   // PUPAE =1 (enable pull-up on all PORTA inputs)
}

char getkey(void){
    PORTA = 0xe0;       // selects row 0     
    if ((PORTA & 1) == 0){
    cmdwrt(0x01);
      delay(20);
      if ((PORTA & 1) == 0) return('L');//true if '1' key still active after 20 ms
    }
    PORTA = 0xd0;
    if ((PORTA & 1) == 0){
    cmdwrt(0x01);
      delay(20);
      if ((PORTA & 1) == 0) return('S');//true if '1' key still active after 20 ms
    }
    PORTA = 0xb0; 
    if ((PORTA & 1) == 0){
    cmdwrt(0x01);
      delay(20);
      if ((PORTA & 1) == 0) return('R');//true if '1' key still active after 20 ms
    }

dedndave

i am not familiar with the HCS12 - lol
probably not many in here are - this is more or less a windows programming forum (with a little linux)

but, by looking at the code, i am guessing that the keypad is 4x4 multiplexed (one row unused?)
the upper 4 bits of PortA scan through the rows
the keypad columns are then read on the lower 4 bits of PortA
when a key (switch) is closed, the low signal on the row pulls down the associated column line

what we need is a little more detail on the hardware
that is - a schematic of the current circuit would be nice
and - some idea of the "sensors" that you would like to replace the keypad with

ohhh - it's a 68HCS12
that one, i have heard of   :P

dedndave

also - the desired sensor-to-letter translations would be good

it looks like a pretty simple mod as far as the code is concerned
you merely need to read the port(s) that are attached to the sensors and translate them to letters
if you have a lot of sensor-to-letter combinations, a table might be used
if you only have a few, you can do it in conditional code

kayduhbk

Yeah, sorry its the 68HCS12.  I'm not very good with the lingo, not so good with the programming either (I work in finance, no where near an engineer or a programmer... just doing this for fun)...

Yeah the last row is unused, this code was originally just a keypad displaying what key was pushed.  I figured I could just rework and manipulate it to what I needed.  I am actually trying to manipulate the program to be used as a line follower robot.  My logic behind trying to use this code was:

1. change the buttons on the keypad to signify L, R, S (left, right and straight)
2. change the input from being the pressing of a key pad, to the active low signal sent from the sensor to display the L, R, S
3. change the if statement that's displaying L,R,S with functions that make the servo motors turn to go the different directions.

And from that I was hoping it would make it work, this logic all worked in my head how it's actually going to pan out i'm not so sure.

I attached the "data sheet" of the sensor I have, this was the only documentation they had on the sensor their exact words were "There is no datasheet for it as its a very simple sensor. It gives digital output based on sensor input. Potentiometers on circuit can be used to control sensing range."

Can you explain what you mean by sensor-to-letter translations?

What I was thinking was if there was some way, lets say the sensors outputs were hooked up to pin 0, 1 and 2 to keep the program in a loop to check individually if the low signal was coming from 0, 1 or 2 to run the servos and if the sensor moves when it switches the low state to a different pin it would change to a different function making the servos act differently.

dedndave

well, this is an x86 ASM forum, and you have a motorola program written in C - lol
but, it's your lucky day - i am an Electronics Engineer
and, while i haven't written any code for that specific controller, i have written code for the 6800 series
i am not a C guy, either - the code i wrote was assembler, of course
but i can work through that

when you say "sensor", that covers a lot of ground in the electronics world
maybe you can show me the manufacturer and model number or some details of any kind
is it a switch ? - i don't know - i can't tell you how to connect it to a port or how to write code without some info
you say you attached the data sheet, but i don't see any attachment

what i can do is make some assumptions about how the program works
and - it may help you understand a few basic principles

for example, the key-scan thing is probably done in a "round-robin" fashion
i.e., the program may go off and do other things, but it does them in a loop
on each pass of the loop, the key-scan write-then-read sequence is used to read the keypad

what i meant by sensor-to-letter translations is,
what input sensor value(s) translate to what letters
i see, now, that there are only a few letters to be used - so it seems pretty simple
but, i still need some kind of info on the sensor before i can offer any suggestions   :P

kayduhbk

i could have sworn that i attached a pdf file that the website I purchased the sensor from  sent me, i'll try again. 

http://www.robokits.co.in/documentation/Line_Sensor_Array.pdf

Didnt realize it only allowed zip files, thats the direct link to the "data sheet" they gave me.

dedndave

that worked

i have never played with a "line follower"   :P
but, it seems simple enough

you have a 7-element detector - so, you want the middle one to be "active" and the others to be "inactive"
the logic reverses if you have a black line on a white background or a white line on a black background

so, you might see....
0001000, 0011100, 0111110, 1000001, 1100011, or 1110111 (indicates you are following the line)
if you see the odd signal in the lower bits, you want to turn one way
if you see the odd signal in the higher bits, you want to turn the other way

http://extremeelectronics.co.in/avr-tutorials/line-following-robot-using-avr-atmega8/

you will like that website - they have a lot of info on what you want to do
as you can see on that page, they have a video of a little robot car that follows a line