本程序为为做笔记之用,不是太规范。
因为需要将各种数组都定义到外部RAM中,所以需要做一些设置。设置外部RAM地址为0x60000000,长度为0X8000(32KByte).新建RAM.h,main.c,ram.c
源代码如下:
main.c
#include "ram.h"
typedef unsigned char datatype;
void SetNull(sequeue *sq)
{
sq->front=0;
sq->rear=0;
}
datatype Empty(sequeue *sq)
{
if(sq->rear==sq->front)return(1);
else return(0);
}
datatype GetFront(sequeue *sq)
{
if(Empty(sq))
{
//printf("queue is null");
return(NULL);
}
else
return(sq->buf[(sq->front+1)%maxsize]);
}
datatype InQueue(sequeue *sq,datatype x)
{
if((sq->rear+1)%maxsize==sq->front)
{
//printf("队列已满");
return(NULL);
}
else
{
sq->buf[sq->rear]=x;
sq->rear=(sq->rear+1)%maxsize;
return(1);
}
}
datatype DeQueue(sequeue *sq)
{
unsigned char byt;
if(Empty(sq))
{
//printf("队列为空");
return(NULL);
}
else
{
byt = sq->buf[sq->front] ;
sq->front=(sq->front+1)%maxsize;
return byt;
}
}
int main(void)
{
unsigned char *ptr;
unsigned long i,j;
unsigned char arry[200];
sequeue *sq;
sq=&esq; SetNull(sq);
for(i=0;i<maxsize;i++)
{
InQueue(sq,0xdd);
}
for(i=0;i<maxsize;i++)
{
if(!Empty(sq))
arry
=DeQueue(sq);
else
arry[199]=0xff;
}
for(i=0;i<maxsize;i++)
{
InQueue(sq,0xcc);
}
for(i=0;i<maxsize;i++)
{
if(!Empty(sq))
arry=DeQueue(sq);
else
arry[199]=0xff;
}
ptr=x_unskip;
for(j=0;j<0x4000;j++) //监视器恢复标志位(16384字节)
{
*ptr=0xff;
ptr++;
}
ptr=x_arm_flg;
for(i=0;i<128;i++)
{
*ptr=i;
ptr++;
}
ptr=x_alarm_link_flg;
for(i=0;i<128;i++)
{
*ptr=i;
ptr++;
}
x_video_loss_mon=32;
x_system_control=0;
ptr=x_group_mon;
for(i=0;i<64;i++)
{
*ptr=0;
ptr++;
}
ptr=x_group_cam;
for(j=0;j<3072;j++)
{
*ptr=0;
ptr++;
}
ptr=x_mon_dtime;
for(i=0;i<128;i++)
{
*ptr=0x03;
ptr++;
}
ptr=x_group_switch;
for(j=0;j<256;j++)
{
*ptr=0x00;
ptr++;
}
/*
ptr=(uchar xdata *)RAM_ON_DUTY_ACTION; //On/Off Duty Action(3584字节)
for(j=0;j<3584;j++)
{
*ptr=0x00;
ptr++;
} */
ptr=x_cam_now_num;
for(i=0;i<128;i++)
{
*ptr=0x00;
ptr++;
*ptr=i;
ptr++;
}
return 0;
}
ram.c:
#include "ram.h"
uchar x_unskip[16384];
uchar x_alarm[256];
uchar x_arm_flg[128];
uchar x_alarm_link_flg[128];
uchar x_video_loss_mon;
uchar x_system_control;
uchar x_group_mon[64];
uchar x_group_cam[3072];
uchar x_prog_track[128];
uchar x_video_loss_flg[128];
uchar x_mon_vtime[128];
uchar x_mon_dtime[128];
uchar x_group_switch[256];
uchar x_alarm_link[4096];
uchar x_virtual_numh[1024];
uchar x_virtual_numl[1024];
uchar x_cam_now_num[256];
uchar x_group_dtime[16];
uchar x_sys_info[6];
uchar x_clock_display_mode;
uchar x_char_display_mode;
uchar x_key_login[32];
uchar x_mon_run_mode[128];
uchar x_prog_switch[1024];
//特别注意结构体变量的定义与外部引用,很容易编译处错误。
sequeue esq;
ram.h:
#define uint8 unsigned char
#define NULL 0
#define maxsize 193
typedef struct seq
{
uint8 buf[maxsize];
uint8 front;
uint8 rear;
}sequeue;
typedef unsigned char uchar;
extern sequeue esq ;
extern unsigned char x_unskip[16384];
extern uchar x_alarm[256];
extern uchar x_arm_flg[128];
extern uchar x_alarm_link_flg[128];
extern uchar x_video_loss_mon;
extern uchar x_system_control;
extern uchar x_group_mon[64];
extern uchar x_group_cam[3072];
extern uchar x_prog_track[128];
extern uchar x_video_loss_flg[128];
extern uchar x_mon_vtime[128];
extern uchar x_mon_dtime[128];
extern uchar x_group_switch[256];
extern uchar x_alarm_link[4096];
extern uchar x_virtual_numh[1024];
extern uchar x_virtual_numl[1024];
extern uchar x_cam_now_num[256];
extern uchar x_group_dtime[16];
extern uchar x_sys_info[6];
extern uchar x_clock_display_mode;
extern uchar x_char_display_mode;
extern uchar x_key_login[32];
extern uchar x_mon_run_mode[128];
extern uchar x_prog_switch[1024];
还有需要注意的地方是结构体变量引用时:如果通过指针引用,那么需要现定义一个结构体指针,然后将结构体的首地址赋给指针。引用时采用P->结构体成员的方式。如果直接引用,采用结构体变量.结构体成员的方式。