brandon white


Discussion created by brandon white on May 15, 2011
Latest reply on May 27, 2011 by brandon white

Hello everyone


Im brand new to programming micro controllers and I'm having trouble getting my MC9S12DG256B to talk to a GUI I am designing on my computer. What I'm trying to do is send information from the ADC to the computer through the SCI, and then allow the GUI on the computer to set different variables in my MCU via SCI as well. Like I said I'm really new to this and just started getting some of the concepts down. So here is my code. 

#include <hidef.h>      /* common defines and macros */#include "derivative.h"      /* derivative-specific definitions */void SciConfig(void);void CharOut(char);void delay(int);void init_ATD(void);void DataOut(int);void init_PLL(void);int input(void);//****Main****//void main(void) {char D = 0x80; int B = 0x01;  int adcMid; int adcData; int inData; int adcEnd;  init_PLL();  // for running board without code warriorinit_lcd4(); // initiates LCD displaySciConfig();// configures SCI for outputinit_ATD(); //initiates  ATD converterDDRJ |= 0x02; PTJ &= 0x02; DDRB = 0xFF; ATD0CTL5 = 0x25; //starts conversion  and continuousely scans chanells                            for(;;){   delay(50);     //wait for just a sec DataOut(ATD0DR0H);  PORTB = ATD0DR0H;  delay(500);   if ((SCI0SR1 & 0x20) ==  0){  inData = input();  PORTB = inData;   lcd_printd(inData);   delay(500);   }  }}//*****Functions*****////configures SCI for output. 9600 buad ratevoid SciConfig(){   SCI0BDH= 0x00;  SCI0BDL = 0x9C;   //baud rate to 9600  SCI0CR1 =0x24;  SCI0CR2 =0x0C; // enable transmit and recieve}//functions to pass variables for output to COM portvoid CharOut(char c){      while ((SCI1SR1 & 0x80) ==0)  //waits for data to be send and trasmit reg empty    //waits for data to be sent   SCI0DRL=c;   delay(50);}void DataOut(int val){  while((SCI0SR1 & 0x80)==0){  }//wait for data to be sent  SCI0DRL = val;  delay(50);}    int input() {  while((SCI0SR1 & 0x20) == 0); {  }  return SCI0DRL;}// delay for 'del' msecsvoid delay(int del){    int i,j; for(i=0; i<del; i++)    for(j=0; j<4000; j++);}//initilizes ATD convertervoid init_ATD( ){   ATD0CTL2 = 0xC0; // 1100 0000 -- ADC On = 1, AFFC = 1, ASCIE = 0   delay(1);   // waits for LCD warm up (actually only needs 5 us)   ATD0CTL3 = 0x88; // 0 0001 000 -- one conversion per sequence   ATD0CTL4 = 0x8B; // 1 00 01011 - 8-bit resoln, 2 A/D clks, 1 MHz conv. freq}

 My some design specifications: I need the ADC to constintly output to the SCI so the comptuer will have an up to minute reading from it. Also I need the comptuer to be able to set different features on the the MCU.