SCI Module in C?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

SCI Module in C?

4,228 次查看
RChapman
Contributor I
This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.

Posted: Fri May 06, 2005 7:28 pm  

I am trying to quickly evaluate a demo HCs08 GB32 board and I am looking for an SCI module in C or Assembly that would work. Does anyone have a simple SCI module that I can use (it is to drive a Hitachi LCD and test).

Thanks.

Posted: Mon May 16, 2005 3:04 pm    

Hi,

Below is some code designed for an HITACHI LCD display.
It does not use the SCI, but half a PORT to communicate.
You can use the same functions serializing it to go through the SPI or SCI.

 

Code:

void Wait1ms(void){
   asm { 
     PSHX
     PSHH
     LDHX #CONST
     loop:
     AIX #-1  ;2 cycles
     CPHX #0  ;3 cycles
     BNE loop ;3 cycles             
     PULH
     PULX
   }     
}

void Toggle(void){       
/* This function toggles the E(EN) line (LCD). */   
   PTED.byte |=  0x80; 
   PTED.byte &= ~0x80;   
}

void WaitNms(int n){
/* This function waits for N ms. */   
   int i;
   for(i=1;i<=n;i++) Wait1ms();
}

void IOPortInit(void){
   PTED.byte  = 0x00;
   PTEDD.byte = 0xC0;
   PTGD.byte  = 0x00; // R/W (PTG3) set to 0 (W)
   PTGDD.byte = 0xF8;
}

void CommandMode(void){
   PTED.byte &= ~0x40; //RS cleared
}

void DataMode(void){
   PTED.byte |= 0x40;  //RS set
}

void LCD_Init(void)
{
/* Initialisation of the LCD display.
   This LCD is driven by an HITACHI HD44780. */
 
   IOPortInit();
   CommandMode();
   WaitNms(16);
   PTGD.byte  = 0x30;
   Toggle();
   WaitNms(5);
   PTGD.byte  = 0x30;
   Toggle();
   Wait1ms();
   PTGD.byte  = 0x03;   
   Toggle();
   Wait1ms();     
   PTGD.byte  = 0x20; /* function set: change to 4 bits format */
   Toggle();   
   Wait1ms();   
   /* from here, 4-bit format used (always write 4 msb, then 4 lsb ) */     
   PTGD.byte  = 0x20; /* function set: display 2 lines, 5x7 dots  */
   Toggle();   
   PTGD.byte  = 0x80;
   Toggle();   
   Wait1ms();     
   
   PTGD.byte  = 0x00; /* display on/off control: display on, cursor off, blinking off */
   Toggle();   
   PTGD.byte  = 0xC0;
   Toggle();   
   Wait1ms();
   
   PTGD.byte  = 0x00; /* entry mode set */
   Toggle();   
   PTGD.byte  = 0x60;
   Toggle();   
   Wait1ms();     
}

void ReturnHome(void){
/* This function sets the cursor to home position (address 0), then the DDRAM address to 0 */
   CommandMode();
   PTGD.byte  = 0x00;
   Toggle();   
   PTGD.byte  = 0x20;
   Toggle();   
   WaitNms(2);
   CommandMode();
   PTGD.byte  = 0x80;
   Toggle();   
   PTGD.byte  = 0x00;
   Toggle();   
   Wait1ms();
}

void DisplayStringLine(char *str, Bool lowerline){
/* This function stores a string in DDRAM at
   the current DDRAM address. */
   char *strptr;
   strptr = str;

   ReturnHome();
   if (lowerline) {
      CommandMode();
      PTGD.byte  = 0x80 | 0x40; /* set DDRAM address to 0x40 */
      Toggle();
      PTGD.byte  = 0x00;
      Toggle();
   }
   Wait1ms();
   DataMode(); /* Write data to DDRAM */
   while ((*strptr) != '\0'){
       PTGD.byte  = ((*strptr) & 0xF0);
       Toggle();
       PTGD.byte  = (((*strptr) & 0x0F) << 4);
       Toggle();
       Wait1ms();
       strptr++;
   }   
}

void DisplayAutoRotate(void){
/* This function rotates the DDRAM */
   CommandMode();
   for(;:smileywink: {
      PTGD.byte  = 0x10;
      Toggle();
      if (counter < MAXCOUNTER/2){
         PTGD.byte  = 0x80;
      } else {
         PTGD.byte  = 0xC0;
      }
      Toggle();
      WaitNms(150);
   }
}

void main(void)
{   
   int blink = 10;
   asm {
      PSHA;
      LDA #$03;
      STA $1802;
      PULA;
   }

   SOPT.byte = 0x02;  /* Disable COP,STOP, Enable BKGD */
   SBCO.bit.bcoe = 1; /* CLKOUT Enabled */
   PTFDD.byte = 0x0F;
   PTFD.byte = 0x00;
   
   if(SCI1S1.bit.or == 1) PTFD.byte = 0x0F;
   
   while (1) {
         PTFD.byte ^= 0x0F;
         
         WaitNms(200);
      }
   
   Timer_Init();
   LCD_Init();
   while (blink--) {
        DisplayStringLine("*** WELCOME! ***", FALSE);
        DisplayStringLine("                ", TRUE);
        WaitNms(100);
        DisplayStringLine("                ", FALSE);
        WaitNms(100);
   }
   DisplayStringLine ("XXXX, Software Starts Here        ", FALSE);
   DisplayStringLine (" XXXX, Software Starts Here      ", TRUE);
   DisplayAutoRotate();
}




Also LCD manufacturers often give some code. Even if it is not for the S08 core, it may be easier to adapt than the code above, if you absolutely want to go for the SCI.

Finally, by searching Google with the family part number, I always found snippets I could use for my screens.

Enjoy,

Posted: Mon May 16, 2005 3:31 pm    

Sounds like our first "contribution"

Posted: Mon May 16, 2005 4:03 pm    

Well, I'm not proud of it...
It's part of the EVB code I simply copied.

Problem with these LCD is that I'm not sure Commands are similar from one manuacturer to another.
Already command set is different from one display to another within the same brand.

Posted: Mon May 23, 2005 7:15 pm    

read the following aplication note. AN1274. is found on freescale.
Regards-

标签 (1)
0 项奖励
回复
0 回复数