#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include "..\OS\28335cpu\includes.h"
#include "F28335_example.h" // Main include file
// Determine when the shift to right justify the data takes place
// Only one of these should be defined as 1.
// The other two should be defined as 0.
#define POST_SHIFT 0 // Shift results after the entire sample table is full
#define INLINE_SHIFT 1 // Shift results as the data is taken from the results regsiter
#define NO_SHIFT 0 // Do not shift the results
// ADC start parameters
#if (CPU_FRQ_150MHZ) // Default - 150 MHz SYSCLKOUT
#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz
#endif
#if (CPU_FRQ_100MHZ)
#define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) = 25.0 MHz
#endif
#define ADC_CKPS 0x0 // ADC module clock = HSPCLK/1 = 25.5MHz/(1) = 25.0 MHz
#define ADC_SHCLK 0x1 // S/H width in ADC module periods = 2 ADC cycle
#define AVG 1000 // Average sample limit
#define ZOFFSET 0x00 // Average Zero offset
#define BUF_SIZE 360 // Sample buffer size
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
#define TASK_STK_SIZE 30
#define N_TASKS 2
OS_STK TaskStartStk[TASK_STK_SIZE];
OS_STK TaskStk[N_TASKS][TASK_STK_SIZE]; /* Tasks stacks */
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
#define LCD_DATA (*((volatile Uint16 *)0x45EF))
#define EN GpioDataRegs.GPBDAT.bit.GPIO61
#define RW GpioDataRegs.GPADAT.bit.GPIO27
#define RS GpioDataRegs.GPBDAT.bit.GPIO60
#define LOW 0
#define HIGH 1
#define CLEAR_SCREEN 0x01 //ÇåÆáÖ¸áî£oÇåÆáÇòACÖμÎa00H
#define AC_INIT 0x02 //½«ACéèÖÃÎa00H¡£ÇòóαêòÆμ½Ô-μãλÖÃ
#define CURSE_ADD 0x06 //é趨óαêòÆμ½·½Ïò¼°í¼ÏñÕûìåòƶˉ·½Ïò£¨Ä¬èÏóαêóòòÆ£¬í¼ÏñÕûìå2»¶ˉ£©
#define FUN_MODE 0x30 //1¤×÷ģ꽣o8λ»ù±¾Ö¸áî¼ˉ
#define DISPLAY_ON 0x0c //ÏÔ꾿a,ÏÔê¾óα꣬ÇòóαêλÖ÷′°×
#define DISPLAY_OFF 0x08 //ÏÔê¾1Ø
#define CURSE_DIR 0x14 //óαêÏòóòòƶˉ:AC=AC+1
#define SET_CG_AC 0x40 //éèÖÃAC£¬·¶Î§Îa£o00H~3FH
#define SET_DD_AC 0x80
extern const uchar WordLib16x16[]={
0x00,0x00,0x00,0x00,0x0F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x0F,0xD2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x0E,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x02,0x83,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xE7,0xF6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xDF,0xEC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xBF,0xD8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0x7F,0xB8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x06,0xFF,0xB0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x0F,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xFF,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1B,0xFF,0xF0,0x00,0x00,0x0D,0x98,0x0F,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1F,0xFF,0xF0,0x00,0x00,0x09,0x90,0x0C,0xC0,0x00,0x00,0x00,0x00,
0x00,0xAC,0x00,0x57,0xFE,0xF0,0x00,0x00,0x26,0x08,0x03,0x83,0x00,0x00,0x00,0x00,
0x00,0xFF,0x00,0x7F,0xFE,0xF0,0x00,0x00,0x1F,0xFA,0x03,0xBD,0x00,0x00,0x00,0x00,
0x00,0xDF,0x00,0x77,0xFD,0x00,0x00,0x00,0x3D,0xFE,0x03,0x3D,0x00,0x00,0x00,0x00,
0x00,0xBE,0x00,0x77,0xFD,0x00,0x00,0x00,0x2D,0xB6,0x03,0xF5,0x00,0x00,0x00,0x00,
0x00,0x77,0x00,0x67,0xFD,0x00,0x00,0x00,0x29,0xB0,0x07,0xF4,0x00,0x00,0x00,0x00,
0x07,0x7D,0x83,0xFF,0xFF,0x00,0x00,0x00,0x3F,0xB4,0x07,0xFC,0x00,0x00,0x00,0x00,
0x07,0xFD,0x83,0xDF,0xFD,0x00,0x00,0x00,0x1F,0xBE,0x03,0xF4,0x00,0x00,0x00,0x00,
0x06,0xFD,0x83,0xBF,0xFB,0x00,0x00,0x00,0x3F,0xFC,0x03,0xF5,0x00,0x00,0x00,0x00,
0x05,0xFD,0x83,0x7B,0xFB,0x00,0x00,0x00,0x2F,0xF6,0x03,0xFD,0x00,0x00,0x00,0x00,
0x05,0xFC,0x82,0xFB,0xFF,0x00,0x00,0x00,0x2F,0xB0,0x03,0xFD,0x00,0x00,0x00,0x00,
0x1B,0xFF,0x01,0xFB,0xFF,0x00,0x00,0x00,0x2F,0xB0,0x0B,0xF3,0x00,0x00,0x00,0x00,
0x1B,0xFF,0x81,0xFB,0xF9,0x00,0x00,0x00,0x1F,0xB0,0x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xFC,0xFC,0x00,0x1F,0xE7,0xF3,0xFF,0xF1,0x70,0xBF,0xBF,0xC9,0xFB,0x00,
0x13,0x3F,0xF3,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x90,0x00,0x00,0x00,0x04,0x00,
0x00,0xE7,0x9E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x03,0x9C,0x00,
0x00,0xF8,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x01,0x88,0x00,
0x00,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
extern uchar A[]={"ÄϾ©ÑDDñ"};
extern uchar B[]={"μçÆø¿Æ¼¼óDÏT1«Ë¾"};
extern uchar C[]={"www.armdsp.net"};
extern uchar D[]={"www.njyxdq.com"};
extern uchar E[]={"tel:02558747116"};
void LcdInit();
void WriteCmd12864(Uint16 cmd);
void WriteData12864(Uint16 dat);
void delay (Uint16 t);
void configtestled(void);
void InitXintf(void);
void DisplayCgrom(uchar *hz);
void Task(void *data); /* Function prototypes of tasks */
void Task1(void *data);
void OSTickISR();
void scic_echoback_init(void);
void scic_fifo_init(void);
void scic_xmit(int a);
void scic_msg(char *msg);
/*$PAGE*/
/*
*********************************************************************************************************
* MAIN
*********************************************************************************************************
*/
interrupt void ISRTimer0(void);
interrupt void ISRTimer1(void);
interrupt void ISRTimer2(void);
//--- Global Variables
Uint16 AdcBuf[ADC_BUF_LEN]; // ADC data buffer allocation
Uint32 PwmDuty; // Measured PWM duty cycle
Uint32 PwmPeriod; // Measured PWM period
Uint16 p, x,y;
Uint16 LoopCount;
Uint16 ErrorCount;
Uint16 ReceivedChar;
char *msg;
void main(void)
{
//--- CPU Initialization
InitSysCtrl(); // Initialize the CPU
InitPieCtrl(); // Initialize and enable the PIE
//InitPieVectTable();
InitWatchdog(); // Initialize the Watchdog Timer
// InitGpio(); // Initialize the shared GPIO pins
// InitXintf();
InitXintf16Gpio();
InitScibGpio();
configtestled(); // Initialize the external memory interface
#ifdef EXAMPLE_FLASH // EXAMPLE_FLASH, if defined, is in CCS project options
//--- Copy all Flash sections that need to run from RAM (use memcpy() from RTS library)
// Section secureRamFuncs contains user defined code that runs from CSM secured RAM
/* memcpy( &secureRamFuncs_runstart,
&secureRamFuncs_loadstart,
&secureRamFuncs_loadend - &secureRamFuncs_loadstart);
*/
//--- Initialize the Flash and OTP
// InitFlash(); // Initialize the Flash
#endif
DINT;
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &OSTickISR;//ISRTimer0;//
PieVectTable.USER11 = &OSCtxSw;//èÎÎñÇD»»Ä£ÄaÖD¶Ï óÃÖ¸áîasm(" TRAP #30")à′μ÷óÃêμÏÖ
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize the Device Peripheral. This function can be
// found in DSP2833x_CpuTimers.c
InitCpuTimers(); // For this example, only initialize the Cpu Timers
// Configure CPU-Timer 0, 1, and 2 to interrupt every second:
// 150MHz CPU Freq, 1 second Period (in uSeconds)
ConfigCpuTimer(&CpuTimer0, 150, 1000);//3õê¼»ˉÎa1MSÖD¶Ïò»′Î ×÷ÎaOSê±Öó
StartCpuTimer0();
// Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
// which is connected to CPU-Timer 1, and CPU int 14, which is connected
// to CPU-Timer 2:
IER |= M_INT1;
// Enable TINT0 in the PIE: Group 1 interrupt 7
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
// Timer 1 connected to int13 by yang
XIntruptRegs.XNMICR.bit.SELECT= 0;
LoopCount = 0;
ErrorCount = 0;
scic_fifo_init(); // Initialize the SCI FIFO
scic_echoback_init(); // Initalize SCI for echoback
OSInit();
OSTaskCreate(Task1, (void *)0, (void *)&TaskStk[0][0], 1); /* Initialize uC/OS-II */
OSStart();
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
while(1){
}
}
/*
*********************************************************************************************************
* TASKS
*********************************************************************************************************
*/
void Task1(void *data)
{
msg = "\r\n\n\nHello YanXu!\0";
OS_ENTER_CRITICAL();
scic_msg(msg);
msg = "\r\nYou will enter a character, and the DSP will send it back! \n\0";
scic_msg(msg);
OS_EXIT_CRITICAL();
while(1)
{
OSTimeDly(1);
RS=LOW;
delay(25);
RW=LOW;
delay(25);
EN=LOW;
LcdInit();
delay(25);
WriteCmd12864(CLEAR_SCREEN);
delay(250);
WriteCmd12864(0x82);
delay(25);
DisplayCgrom(A);
WriteCmd12864(0x90);
delay(25);
DisplayCgrom(B);
WriteCmd12864(0x88);
delay(25);
DisplayCgrom(C);
WriteCmd12864(0x98);
delay(25);
DisplayCgrom(D);
for(y=0;y<10;y++)
{delay(25000);}
WriteCmd12864(CLEAR_SCREEN);
delay(250);
// while(1){
WriteCmd12864(0x32);
delay(25);
WriteCmd12864(0x36);
delay(25);
for (y=0;y<32;y++)
{ WriteCmd12864(0x80+y); //y
delay(10);
WriteCmd12864(0x80); //X
delay(10);
for(x=0;x<16;x++)
{
WriteData12864( WordLib16x16[y*16+x]);
delay(10); }
}
for (y=0;y<32;y++)
{ WriteCmd12864(0x80+y); //y
delay(10);
WriteCmd12864(0x88); //X
delay(10);
for(x=0;x<16;x++)
{
WriteData12864( WordLib16x16[512+y*16+x]);
delay(10); }
}
for(y=0;y<10;y++)
{delay(25000);}
}
}
void delay (Uint16 t)
{ Uint16 i;
while(t--)
{
for(i=0;i<200;i++)
;
}
}
void LcdInit()
{
delay(2500);
WriteCmd12864(FUN_MODE);
delay(25);
WriteCmd12864(FUN_MODE);
delay(25);
WriteCmd12864(DISPLAY_ON);
delay(25);
WriteCmd12864(CLEAR_SCREEN);
delay(30);
WriteCmd12864(AC_INIT);
delay(20);
}
void WriteCmd12864(Uint16 cmd)
{
// Uint16 i=5;
RS=LOW;
RW=LOW;
EN=HIGH;
LCD_DATA=cmd;
// while(i--);
EN=LOW;
}
void WriteData12864(Uint16 dat)
{ // Uint16 i=5;
RS=HIGH;
RW=LOW;
EN=HIGH;
LCD_DATA=dat;
// while(i--);
EN=LOW;
}
void DisplayCgrom(uchar *hz)
{
while(*hz != '\0')
{
WriteData12864(*hz);
hz++;
delay(10);
}
}
void configtestled(void)
{
EALLOW;
GpioCtrlRegs.GPBMUX2.bit.GPIO60 = 0; // GPIO60 = GPIO60
GpioCtrlRegs.GPBDIR.bit.GPIO60 = 1;
GpioCtrlRegs.GPBMUX2.bit.GPIO61 = 0; // GPIO60 = GPIO60
GpioCtrlRegs.GPBDIR.bit.GPIO61 = 1;
GpioCtrlRegs.GPAMUX2.bit.GPIO27= 0;
GpioCtrlRegs.GPADIR.bit.GPIO27 = 1;
// GpioCtrlRegs.GPBMUX2.bit.GPIO54 = 0; // GPIO60 = GPIO60
// GpioCtrlRegs.GPBDIR.bit.GPIO54 = 1;
EDIS;
}
void scic_echoback_init()
{
// Note: Clocks were turned on to the SCIA peripheral
// in the InitSysCtrl() function
ScibRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
ScibRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
ScibRegs.SCICTL2.all =0x0003;
ScibRegs.SCICTL2.bit.TXINTENA = 1;
ScibRegs.SCICTL2.bit.RXBKINTENA =1;
#if (CPU_FRQ_150MHZ)
ScibRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 37.5MHz.
ScibRegs.SCILBAUD =0x00E7;
#endif
#if (CPU_FRQ_100MHZ)
ScibRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 20MHz.
ScibRegs.SCILBAUD =0x0044;
#endif
ScibRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
}
// Transmit a character from the SCI
void scic_xmit(int a)
{
while (ScibRegs.SCIFFTX.bit.TXFFST != 0) {}
ScibRegs.SCITXBUF=a;
}
void scic_msg(char * msg)
{
int i;
i = 0;
while(msg[i] != '\0')
{
scic_xmit(msg[i]);
i++;
}
}
// Initalize the SCI FIFO
void scic_fifo_init()
{
ScibRegs.SCIFFTX.all=0xE040;
ScibRegs.SCIFFRX.all=0x204f;
ScibRegs.SCIFFCT.all=0x0;
}
//===========================================================================
// No more.
//===========================================================================
|