OpenCores
URL https://opencores.org/ocsvn/light8080/light8080/trunk

Subversion Repositories light8080

[/] [light8080/] [trunk/] [c/] [hello.c] - Diff between revs 65 and 66

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 65 Rev 66
Line 6... Line 6...
//      Writer:                         Moti Litochevski 
//      Writer:                         Moti Litochevski 
//
//
//      Description:
//      Description:
//              This file contains a simple program written in Small-C that sends a string to 
//              This file contains a simple program written in Small-C that sends a string to 
//              the UART and then switches to echo received bytes. 
//              the UART and then switches to echo received bytes. 
 
//              This example also include a simple interrupt example which will work with the 
 
//              verilog testbench. the testbench 
//
//
//      Revision History:
//      Revision History:
//
//
//      Rev <revnumber>                 <Date>                  <owner> 
//      Rev <revnumber>                 <Date>                  <owner> 
//              <comment>
//              <comment>
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
 
 
 
// define interrupt vectors 
 
// note that this file must be edited to enable interrupt used 
 
#include intr_vec.h 
 
// insert c80 assmbly library to the output file 
#include ..\tools\c80\c80.lib
#include ..\tools\c80\c80.lib
 
 
// UART IO registers 
// UART IO registers 
port (128) UDATA;               // uart data register used for both transmit and receive 
port (128) UDATA;               // uart data register used for both transmit and receive 
port (129) UBAUDL;              // low byte of baud rate register 
port (129) UBAUDL;              // low byte of baud rate register 
port (130) UBAUDH;              // low byte of baud rate register 
port (130) UBAUDH;              // low byte of baud rate register 
port (131) USTAT;               // uart status register 
port (131) USTAT;               // uart status register 
// digital IO ports registers 
// digital IO ports registers 
port (132) P1REG;       // output port1 - used as first attenuator control 
port (132) P1DATA;      // port 1 data register 
port (133) P2REG;               // output port2 - used as low digit LCD 
port (133) P1DIR;               // port 1 direction register control 
port (134) P3REG;               // output port3 - used as high digit LCD 
port (134) P2DATA;              // port 2 data register 
port (135) P4REG;               // output port4 
port (135) P2DIR;               // port 2 direction register control 
 
// interrupt controller register 
 
port (136) INTRENA;             // interrupts enable register 
// simulation end register 
// simulation end register 
// writing any value to this port will end the verilog simulation when using tb_l80soc 
// writing any value to this port will end the verilog simulation when using tb_l80soc 
// test bench. 
// test bench. 
port (255) SIMEND;
port (255) SIMEND;
 
 
Line 111... Line 119...
                sendbyte('A'+q-10);
                sendbyte('A'+q-10);
        else
        else
                sendbyte('0'+q);
                sendbyte('0'+q);
}
}
 
 
 
// external interrupt 0 service routine 
 
int0_isr()
 
{
 
        printstr("Interrupt 0 was asserted."); nl();
 
}
 
 
// program main routine 
// program main routine 
main()
main()
{
{
        // configure UART baud rate - set to 9600 for 30MHz clock 
        // configure UART baud rate - set to 9600 for 30MHz clock 
        // BAUD = round(<clock>/<baud rate>/16) = round(30e6/9600/16) = 195 
        // BAUD = round(<clock>/<baud rate>/16) = round(30e6/9600/16) = 195 
        UBAUDL = 195;
//MOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTI
 
//MOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTI
 
//      UBAUDL = 195;
 
        UBAUDL = 1;
 
//MOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTI
 
//MOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTIMOTI
        UBAUDH = 0;
        UBAUDH = 0;
 
 
 
        // configure both ports to output and digital outputs as zeros 
 
        P1DATA = 0x00;
 
        P1DIR = 0xff;
 
        P2DATA = 0x00;
 
        P2DIR = 0xff;
 
        // enable interrupt 0 only 
 
        INTRENA = 0x01;
 
        // enable CPU interrupt 
 
#asm 
 
        ei
 
#endasm
 
 
        // print message 
        // print message 
        printstr("Hello World!!!"); nl();
        printstr("Hello World!!!"); nl();
        printstr("Dec value: "); printdec(tstary[1]); nl();
        printstr("Dec value: "); printdec(tstary[1]); nl();
        printstr("Hex value: 0x"); printhex(tstary[0]); nl();
        printstr("Hex value: 0x"); printhex(tstary[0]); nl();
        printstr("Echoing received bytes: "); nl();
 
 
 
 
        // assert bit 0 of port 1 to test external interrupt 0 
 
        P1DATA = 0x01;
 
 
 
        printstr("Echoing received bytes: "); nl();
        // loop forever 
        // loop forever 
        while (1) {
        while (1) {
                // check if a new byte was received 
                // check if a new byte was received 
                if (getbyte())
                if (getbyte())
                        // echo the received byte to the UART 
                        // echo the received byte to the UART 
                        sendbyte(rxbyte);
                        sendbyte(rxbyte);
        }
        }
}
}
 
 
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
//                                              Th.. Th.. Th.. Thats all folks !!!
//                                              Th.. Th.. Th.. Thats all folks !!!
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.