Programming MC9S12NE64

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Programming MC9S12NE64

1,606 Views
adrt
Contributor I
Hi, I need some help with transferring code which was written for Boarduino to my freescale MC9S12NE64. This code lights up a diode when 'M' is send to microcontroller and doesn't when 'N' is being send. I send it with python script via USB. My diode is connected to PL0, PL1 and PL2 outputs and it is RGB diode. Here is the code that I am talking about: int outPin = 12; // Output connected to digital pin 12 int mail = LOW; // Is there new mail? int val; // Value read from the serial port void setup() { pinMode(outPin, OUTPUT); // sets the digital pin as output Serial.begin(9600); Serial.flush(); } void loop() { // Read from serial port if (Serial.available()) { val = Serial.read(); Serial.println(val); if (val == 'M') mail = HIGH; else if (val == 'N') mail = LOW; } // Set the status of the output pin digitalWrite(outPin, mail); } Pleas help me quick. I know that is silly task for some of you but for me in this moment is quite difficult. Thank you in advance for answer.
Labels (1)
0 Kudos
3 Replies

396 Views
mjbcswitzerland
Specialist V
Hi

Add these defines:

Code:
#define pinMode(outPin, IO)    if (IO == OUTPUT) { DDRL |= outPin; } else { DDRL &= ~outPin; }#define digitalWrite(outPin, state)   if (state == HIGH) { PTL |= outPin; } else { PTL &= ~outPin; }

 Then change outPin to 0x01, 0x02 or 0x04, depending on whether you want it to control PL0, PL1 or PL2

Regards

Mark

www.uTasker.com

0 Kudos

396 Views
adrt
Contributor I
Hi,
I changed the code but it still doesn't work. Now it looks like this:

#include <hidef.h>      /* common defines and macros */
#include <MC9S12NE64.h>     /* derivative information */

#define pinMode(outPin, IO)    if (IO == OUTPUT) { DDRL |= outPin; } else { DDRL &= ~outPin; }
#define digitalWrite(outPin, state)   if (state == HIGH) { PTL |= outPin; } else { PTL &= ~outPin; }

int outPin = 0x01; // Output connected to digital pin 12
int mail = 0; // Is there new mail?
int val; // Value read from the serial port
void main(void) {
 
 
void setup()

pinMode(outPin, OUTPUT);
Serial.begin(9600);
Serial.flush();

 
void loop()
{
// Read from serial port
if (Serial.available())
{
val = Serial.read();
Serial.println(val);
if (val == 'M') mail = 1;
else if (val == 'N') mail = 0;
}
 
// Set the status of the output pin
digitalWrite(outPin, mail);
}
  /* put your own code here */
  EnableInterrupts;

  for(;:smileywink: {} /* wait forever */
  /* please make sure that you never leave this function */
}

Can you change it to make it work ??
0 Kudos

396 Views
Lundin
Senior Contributor IV
What is "OUTPUT" declared as?

Also, if you write 0x01 to DDRL and 0x01 to PTL in the memory map of the debugger, do you get any outputs then? If not, the problem isn't software-related.
0 Kudos