What does this part of the code supposed to do?
if (sign){ ptr = &buf[1]; buf[0] = 0x2D;}else{ ptr = &buf[0];}int2alpha(temp1,ptr);ptr = &buf[0];while(*ptr){ ptr++;}*ptr++ = '.';*ptr++ = fdigit + 0x30;//*ptr++ = 223;*ptr++ = 'i';*ptr++ = 'n';*ptr = 0;cmd2LCD(0xC0);putsLCD(blanks);cmd2LCD(0xC5);putsLCD(&buf[0]);delayby100ms(2);}
Also, could you please use the "Insert code" button( just to the right of the smiley with a hand over its eyes)? It should help preserve your formatting.
#include <hcs12.h>#include <delay.c>#include <stdio.c>#include <lcdUtilDragon12.c>#include <convert.c>#include <vectors12.h>//#include <SetClK.c>#define INTERRUPT __attribute__((interrupt))void INTERRUPT rtiISR(void);void waitfor20us(void);void openAD0(void);char buf[8];char *msg1 = "Distance = ";char *blanks = " ";char segPat[13] = {0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x67,0x3F, 0x06,0x5B,0x4F};char digit[4]={0xFE,0xFD,0xFB,0xF7}; char digits[9]= {0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67}; int temp1,temp2,count1,count2,time,seq,ix,count ; char sign,fdigit,frem; char *ptr; char i,p;int main(){ DDRB= 0xFF; // configure Port B for output DDRP= 0x0F; delayby100ms(2); openLCD(); openAD0(); cmd2LCD(0x80); putsLCD(msg1); seq = 0; ix = 0; count = 400; asm("ldd #rtiISR"); asm("pshd"); asm("ldd #56"); asm("ldx 0xEEA4"); asm("jsr 0,x"); RTICTL = 0x40; //RTI interrupt interval set to 2**10 OSCCLK cycles DDRB = 0xFF; //configure Port B for output DDRP = 0xFF; //configure Port P for output // CRGINT |= RTIE;//enable RTI interrupt asm("CLI"); //enable interrupt globally //while(1); while(1) { sign = 0; ATD0CTL5 = 0x86; while(!(ATD0STAT0 & SCF)); temp1 = (ATD0DR0 * 10) / 50; if (temp1 < 30) { CRGINT |= RTIE; // asm("CLI"); //PTJ=0xfd; PTB=0xff; // delayby100ms(2); //PTJ=0x00; PTB=0x00; //delayby100ms(5); // count1 ++; // delayby100ms(5); } if (sign) { ptr = &buf[1]; buf[0] = 0x2D; } else ptr = &buf[0]; int2alpha(temp1,ptr); ptr = &buf[0]; while(*ptr) ptr++; *ptr++ = '.'; *ptr++ = fdigit + 0x30; //*ptr++ = 223; *ptr++ = 'i'; *ptr++ = 'n'; *ptr = 0; cmd2LCD(0xC0); putsLCD(blanks); cmd2LCD(0xC5); putsLCD(&buf[0]); delayby100ms(2); }}void openAD0(void){ ATD0CTL2 = 0xE0; ATD0CTL3 = 0x0A; ATD0CTL4 = 0x25; delayby10us(2);}void waitfor20us(void){ TSCR1 = 0x90; TSCR2 = 0; TIOS |= OC0; TC0 = TCNT + 480; while(!(TFLG1 & C0F));}void INTERRUPT rtiISR(void) { CRGFLG = 0x80; // clear RTIF bit PTB = segPat[seq+ix]; PTP = digit[ix]; ix++; if (ix == 4) ix = 0; count--; if(count == 0){ seq++; count = 400; } if(seq == 10) seq = 0;}
Hello,
It is unorthodox to #include any code generating .c files. Normally, only the required header .h files would be included. A header file should not generate any code.
Regards,
Mac
That part of the code is configuring the LCD screen so that I can display the distance.