📄 example_281xgpioloopback.c
字号:
//###########################################################################
//
// FILE: Example_281xGpio.c
//
// TITLE: DSP281x GPIO Loopback Test
//
//
// This program requires the DSP281x V1.00 header files.
// As supplied, this project is configured for "boot to H0" operation.
//
// To work properly this test requires hardware configuration described
// below.
//
// In this test, 8 bits of a GPIO Port are configured as outputs
// and 8 bits of the same port are configured as inputs. The pins
// configured as outputs need to be externally looped back to the
// pins configured as inputs. The output data is read back on the
// input pins. These tests are repeated for various qualifier
// values and for GPIO ports A, B and F.
//
// Similar tests could be written for GPIO ports D, E and G.
// Tests for ports A, D and F are called by separate functions
// An external loopback has to be established before a testcase for
// a given port is executed.
// Refer to the .ebss space for global variables for test status
// If PASS_flag = 0xDOBE then all tests have passed.
// If PASS_flag = 0xDEAD then some tests have failed.
// Tests are self validating. If a test passes, Test_status array
// will have Test code 0x00xx. If this array has 0xDEAD, the test
// has failed.
// Test #1:
// Configure Upper 8 bits of Port A as outputs and lower 8 bits as inputs
// Loop back bits [15:8] to bits [7:0]
// Input Qualifier = 0 (Don't set any input qualifier)
// Needs a delay between CLEAR/SET/TOGGLE instruction.
// This test is run 4 times.
// Test #2:
// Configure Upper 8 bits of Port A as inputs and lower 8 bits as outputs
// Loop back bits [7:0] to bits [15:8]
// Input Qualifier = 0 (Don't set any input qualifier)
// Needs a delay between CLEAR/SET/TOGGLE instruction.
// This test is run 4 times.
// Test #3:
// Configure Upper 8 bits of Port A as outputs and lower 8 bits as inputs
// Loop back bits [15:8] to bits [7:0]
// Input Qualifier, QUALVAL = 1
// Needs a delay between CLEAR/SET/TOGGLE instruction.
// For a pass, the delay must be >= ( 6 * 2 * QUALVAL ) CPUCLK cycles
// i.e the delay must be >= 12 CPUCLK cycles
// This test is run 4 times.
// Test #4:
// Configure Upper 8 bits of Port B as outputs and lower 8 bits as inputs
// Loop back bits [15:8] to bits [7:0]
// Input Qualifier, QUALVAL = 2
// Needs a delay between CLEAR/SET/TOGGLE instruction.
// For a pass, the delay must be >= 24 CPUCLK cycles
// This test is run 4 times.
// Test #5:
// Configure Upper 7 bits of Port F as outputs and lower 8 bits as inputs
// Loop back bits [14:8] to bits [6:0], also loopback bit 8 to bit 7
// Needs a delay between CLEAR/SET/TOGGLE instruction.
// This test is run 4 times.
//###########################################################################
//
// Original Author: T.N.P
//
// Ver | dd mmm yyyy | Who | Description of changes
// =====|=============|======|===============================================
// 1.00| 11 Sep 2003 | L.H. | No change since previous version (v.58 Alpha)
//###########################################################################
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
#include "caidan.h"
#include "zimo.h"
//bluemoon test code
#define E *((int*)(0x2800))
#define RS GpioDataRegs.GPADAT.bit.GPIOA11
#define WR GpioDataRegs.GPADAT.bit.GPIOA10
#define CS1 GpioDataRegs.GPADAT.bit.GPIOA8
#define CS2 GpioDataRegs.GPADAT.bit.GPIOA9
#define DB GpioDataRegs.GPADAT.all
#define KEY1 GpioDataRegs.GPBDAT.bit.GPIOB0
#define KEY2 GpioDataRegs.GPBDAT.bit.GPIOB1
#define KEY3 GpioDataRegs.GPBDAT.bit.GPIOB2
#define LCD_ON 63
#define LCD_OFF 62
#define LIE 0x40
#define PAGE 0xb8
#define NULL 0
#define LCD_LEFT() {CS1=1;CS2=0;}
#define LCD_RIGHT() {CS1=0;CS2=1;}
void lcd_display(int*,int);
void lcd_display2(int*,int);
void caidan_ini(void);
void update(void);
void love_basketball(void); //JUST FOR TEST
void key1_process(void);
void key2_process(void);
void key3_process(void);
void screen_ini(void);
struct caidan screen_main,screen_sport;
struct caidan *current_candan;
int selected_item;
//bluemoon
// Prototype statements for functions found within this file.
void Gpio_select(void);
//bluemoon test code
void lcd_command(char);
void lcd_data(char);
void delay(int);
//void lcd_test();
void lcd_read();
int abc,b1,b2,b3;
//int c_d=0;
//int data1=63;
//int data2=0x00ff;
//int page=0xb8;
//int lie=0x40;
int while1=1;
unsigned char status;
//bluemoon
void main(void)
{
// Step 1. Initialize System Control registers, PLL, WatchDog,
// peripheral Clocks to default state:
// This function is found in the DSP281x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP281x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP281x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP281x_DefaultIsr.c.
// This function is found in DSP281x_PieVect.c.
InitPieVectTable();
Gpio_select();
caidan_ini();
screen_ini();
LCD_LEFT();
update();
b1=0;
b2=0;
b3=0;
while(while1)
{
asm(" NOP");
asm(" NOP");
asm(" NOP");
if(KEY2==0)
{delay(1000);
if(KEY2==0)
{
while(KEY2==0)
asm(" NOP");
key3_process();
b2=b2+1;
}
}
if(KEY3==0)
{
delay(2000);
if(KEY3==0)
{while(KEY3==0)
asm(" NOP");
key2_process();
b3=b3+1;
}
}
if(KEY1==0)
{delay(80);
if(KEY1==0)
{
while(KEY1==0)
asm(" NOP");
key1_process();
b1=b1+1;
}
}
}
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP281x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
// Step 5. User specific code
// lcd_test();
// Tests #1, #2, #3
// Step 6. IDLE loop. Just sit and loop forever (optional):
// for(;;);
}
// Step 7. Insert all local Interrupt Service Routines (ISRs) and functions:
void Gpio_select(void)
{
EALLOW;
GpioMuxRegs.GPAMUX.all=0x0000; // Configure MUXs as digital I/Os or
GpioMuxRegs.GPBMUX.all=0x0000; // peripheral I/Os
GpioMuxRegs.GPADIR.all=0xffff; // GPIO PORTs as output
GpioMuxRegs.GPBDIR.all=0x0000; // GPIO DIR select GPIOs as output
GpioMuxRegs.GPAQUAL.all=0x0000; // Set GPIO input qualifier values
GpioMuxRegs.GPBQUAL.all=0xff;
EDIS;
}
//===========================================================================
// No more.
//===========================================================================
void lcd_command(char cmd)
{ unsigned char temp;
E=0;
asm(" RPT #50|| NOP");
RS=0;
WR=0;
asm(" RPT #30|| NOP");
temp=DB;
temp=temp&0xff00;
temp=temp+cmd;
DB=temp;
asm(" RPT #30|| NOP");
E=1;
asm(" RPT #150|| NOP");
E=0;
delay(5);
}
void lcd_data(char data)
{unsigned char temp;
E=0;
asm(" RPT #50|| NOP");
RS=1;
WR=0;
asm(" RPT #30|| NOP");
temp=DB;
temp=temp&0xff00;
temp=temp+data;
DB=temp;
asm(" RPT #30|| NOP");
E=1;
asm(" RPT #150|| NOP");
E=0;
delay(5);
}
void delay(int count)
{
int i;
for(i=0;i<count;i++)
asm(" RPT #250|| NOP");
}
void lcd_read()
{
E=0;
asm(" RPT #50|| NOP");
RS=0;
WR=1;
asm(" RPT #30|| NOP");
status=DB;
asm(" RPT #30|| NOP");
E=1;
asm(" RPT #150|| NOP");
E=0;
status=DB;
}
void lcd_display(int* pt,int row)
{
int i;
lcd_command(LCD_ON);
lcd_command(LIE);
lcd_command(PAGE+row);
for(i=0;i<64;i++)
{
lcd_data(pt[i]);
}
lcd_command(LIE);
lcd_command(PAGE+row+1);
for(i=64;i<128;i++)
{
lcd_data(pt[i]);
}
}
void lcd_display2(int* pt,int row)
{
int i;
lcd_command(LCD_ON);
lcd_command(LIE);
lcd_command(PAGE+row);
for(i=0;i<64;i++)
{
lcd_data(pt[i]^0xff);
}
lcd_command(LIE);
lcd_command(PAGE+row+1);
for(i=64;i<128;i++)
{
lcd_data(pt[i]^0xff);
}
}
void caidan_ini()
{screen_main.item[0]=jiemian11;
screen_main.item[1]=jiemian12;
screen_main.item[2]=jiemian12;
screen_main.item[3]=jiemian14;
screen_main.next_caidan[0]=&screen_sport;
screen_main.next_caidan[1]=NULL;
screen_main.next_caidan[2]=NULL;
screen_main.next_caidan[3]=NULL;
screen_main.pre_caidan=NULL;
screen_main.p_func[0]=NULL;
screen_main.p_func[1]=NULL;
screen_main.p_func[2]=NULL;
screen_main.p_func[3]=NULL;
screen_sport.item[0]=sport1;
screen_sport.item[1]=sport2;
screen_sport.item[2]=NULL;
screen_sport.item[3]=NULL;
screen_sport.next_caidan[0]=NULL;
screen_sport.next_caidan[1]=NULL;
screen_sport.next_caidan[2]=NULL;
screen_sport.next_caidan[3]=NULL;
screen_sport.pre_caidan=&screen_main;
screen_sport.p_func[0]=love_basketball;
screen_sport.p_func[1]=love_basketball;
selected_item=0;
current_candan=&screen_main ;
}
void update()
{ if(current_candan->item[0]!=NULL)
lcd_display(current_candan->item[0],0);
else
lcd_display(background,0);
if(current_candan->item[1]!=NULL)
lcd_display(current_candan->item[1],2);
else
lcd_display(background,2);
if(current_candan->item[2]!=NULL)
lcd_display(current_candan->item[2],4);
else
lcd_display(background,4);
if(current_candan->item[3]!=NULL)
lcd_display(current_candan->item[3],6);
else
lcd_display(background,6);
switch(selected_item)
{case 0:
lcd_display2(current_candan->item[0],0);
break;
case 1:
lcd_display2(current_candan->item[1],2);
break;
case 2:
lcd_display2(current_candan->item[2],4);
break;
case 3:
lcd_display2(current_candan->item[3],6);
break;
default:
break;
}
}
void love_basketball()
{
asm(" NOP");
}
void key1_process()
{
if(current_candan->item[(selected_item+1)%4]!=NULL)
{
selected_item=(selected_item+1)%4;
}
else
selected_item=0;
update();
}
void key2_process()
{
if(current_candan->next_caidan[selected_item]!=NULL)
{
current_candan=current_candan->next_caidan[selected_item];
selected_item=0;
update();
}
else
{ if(current_candan->p_func[selected_item]!=NULL)
(*(current_candan->p_func[selected_item]))();
}
}
void key3_process()
{
if(current_candan->pre_caidan!=NULL)
{
current_candan=current_candan->pre_caidan;
selected_item=0;
update();
}
}
void screen_ini()
{
LCD_LEFT();
lcd_display(background,0);
lcd_display(background,2);
lcd_display(background,4);
lcd_display(background,6);
LCD_RIGHT();
lcd_display(background,0);
lcd_display(background,2);
lcd_display(background,4);
lcd_display(background,6);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -