/*************************************************************
**  file:         cm3.c
**  description:  The file contains the main program to
**                read and write the 82527 registers.
*************************************************************/
#include <stdio.h>
#include <hc11.h>
#include "delay.h"
#include "lcd.h"

/*******************************
** Variables
*******************************/
unsigned int x;
unsigned char cs;

/*************************************************/
/* Define a structure to for the 82527 registers */
/*************************************************/
typedef struct
{
   unsigned char r[256];
} sCANreg;

/*************************************************/
/* Define a pointer to the 82527 registers       */
/*************************************************/
sCANreg *pCANr;

void main(void)
{
        /*************************************
        * Set the structure to point to the
        * base address of the 82527
        *************************************/
        pCANr = (sCANreg *)0x5000;

        /*************************************
        * Set the 82527 reset line low to 
        * start the reset. Delay 15 msec.
        *************************************/
        PORTA = PORTA & ~0x40;
        /*************************************
        * Power on delay for LCD, then
        * initialize the LCD and display a
        * header. Also completes 82527 reset.
        *************************************/
        DelayMilliSec( 15 );
        PORTA |= 0x40;   /* 82527 reset hi */
        InitLCD();
        SetLCD( LINE1 ); printf( "    CANTEC11    " );
        SetLCD( LINE2 ); printf( "Software Dev SBC" );
        SetLCD( LINE3 ); printf( "----------------" );
        SetLCD( LINE4 ); printf( " 82527 Interface" );

        /*************************************
        * Delay 2 second
        *************************************/
        for( x=0; x<10; x++ )
            DelayMilliSec( 200 );

        ClearLCD();     /* clear the display */

        x = 0;
        while( 1 )
        {
           SetLCD( LINE1 );
           printf( "x = %d ", x++ );
           SetLCD( LINE3 );
           pCANr->r[2] = 1;
           pCANr->r[0x17] = 0x77;
           cs = qcReadRegister( 0 ); printf( "%02x ", cs );
           cs = qcReadRegister( 0x17 ); printf( "%02x ", cs );
           cs = qcReadRegister( 0x18 ); printf( "%02x ", cs );
           cs = qcReadRegister( 0x19 ); printf( "%02x ", cs );
           DelayMilliSec( 250 );
        }
}


#include "vectors.c"
