广东工业大学嵌入式实验报告12.docx
《广东工业大学嵌入式实验报告12.docx》由会员分享,可在线阅读,更多相关《广东工业大学嵌入式实验报告12.docx(12页珍藏版)》请在冰豆网上搜索。
广东工业大学嵌入式实验报告12
嵌入式系统实验报告
学生学院计算机学院
专业班级计算机科学与技术班
学号
学生姓名
指导教师
2010年月日
实验二:
I/O端口的使用和中断处理程序
实验项目性质:
普通
所属课程名称:
嵌入式系统
实验计划学时:
2
一、实验目的:
了解ARM的I/O端口使用和编程方法,了解中断响应处理的过程和中断编程的方法。
二、实验内容和要求:
1.对P01进行控制,周期性(0.5秒)输出高低电平,使得其连接的发光二极管周期性地闪动。
2.读取INT0的按键状态,当其按下改变发光二极管周期性地闪动周期改为0.25秒。
3.INT0作为中断信号接受端,对其短按一下即触发中断,使发光二极管周期性地闪动周期变为1秒,再对其短按一下,又恢复闪动周期为0.5秒
三、实验主要仪器设备和材料:
1.嵌入式系统实验箱,微机
四、实验方法、步骤及结构测试:
1.编程:
端口初始化,软件定时,中断处理。
编程要点:
#include
#include
#include"2410addr.h"
#include"def.h"
voidLed1_On_or_Off(intflag);
voidLed4_On_or_Off(intflag);
voidEINT0_Enable(intflag);
voidC_Entry()
{
inti;
EINT0_Enable(TRUE);
while(10);
;
}
voidEINT0_LISR(void)
{
inti;
Led4_On_or_Off(TRUE);
while(i++<100000);
Led4_On_or_Off(FALSE);
while(i++<10000);
}
voidLed1_On_or_Off(intflag)
{
inttemp;
if(flag==TRUE)//led1on
{
//setGPF4
temp=rGPFCON;
rGPFCON=temp|(1<<8);
temp=rGPFDAT;
rGPFDAT=temp&(0<<4);
}
else//led1off
{
//setGPF4
temp=rGPFCON;
rGPFCON=temp|(1<<8);
temp=rGPFDAT;
rGPFDAT=temp|(1<<4);
}
}
voidLed4_On_or_Off(intflag)
{
inttemp;
if(flag==TRUE)//led1on
{
//setGPF7
temp=rGPFCON;
rGPFCON=temp|(1<<14);
temp=rGPFDAT;
rGPFDAT=temp&(0<<7);
}
else//led1off
{
//setGPF7
temp=rGPFCON;
rGPFCON=temp|(1<<14);
temp=rGPFDAT;
rGPFDAT=temp|(1<<7);
}
}
voidEINT0_Enable(intflag)
{
inttemp;
if(flag==TRUE)
{
//setGPF0
temp=rGPFCON;
rGPFCON=temp|0x2;
temp=rGPGUP;
rGPFDAT=temp|0x1;
rINTMSK&=~(BIT_EINT0);
}
else
{
rINTMSK&=BIT_EINT0;
}
}
2.编译程序
3.调试
五、实验报告要求:
1.试验程序流程图
2.带注解的程序清单
程序清单:
voidC_Entry()
{
inti;
EINT0_Enable(TRUE);
while(10);
;
}
voidEINT0_LISR(void)
{
inti;
Led4_On_or_Off(TRUE);
while(i++<100000);
Led4_On_or_Off(FALSE);
while(i++<10000);
}
voidLed1_On_or_Off(intflag)
{
inttemp;
if(flag==TRUE)//led1on
{
//setGPF4
temp=rGPFCON;
rGPFCON=temp|(1<<8);
temp=rGPFDAT;
rGPFDAT=temp&(0<<4);
}
else//led1off
{
//setGPF4
temp=rGPFCON;
rGPFCON=temp|(1<<8);
temp=rGPFDAT;
rGPFDAT=temp|(1<<4);
}
}
voidLed4_On_or_Off(intflag)
{
inttemp;
if(flag==TRUE)//led1on
{
//setGPF7
temp=rGPFCON;
rGPFCON=temp|(1<<14);
temp=rGPFDAT;
rGPFDAT=temp&(0<<7);
}
else//led1off
{
//setGPF7
temp=rGPFCON;
rGPFCON=temp|(1<<14);
temp=rGPFDAT;
rGPFDAT=temp|(1<<7);
}
}
voidEINT0_Enable(intflag)
{
inttemp;
if(flag==TRUE)
{
//setGPF0
temp=rGPFCON;
rGPFCON=temp|0x2;
temp=rGPGUP;
rGPFDAT=temp|0x1;
rINTMSK&=~(BIT_EINT0);
}
else
{
rINTMSK&=BIT_EINT0;
}
}
实验三:
LCD显示与触摸屏
实验项目性质:
普通
所属课程名称:
嵌入式系统
实验计划学时:
2
一、实验目的:
学习LCD显示和触摸屏的编程方法。
二、实验内容和要求:
1.在彩色LCD显示屏上显示数字和汉字以及画图。
2.触摸屏编程,触摸位置信息的检测
3.编程实现,任点触摸屏一下,即在该处显示该处的x,y坐标数据。
三、实验主要仪器设备和材料:
嵌入式系统实验箱,微机
四、实验方法、步骤及结构测试:
1.编程要点与相关函数
a)画点:
intsetpixel(intx,inty,unsignedshortpencolor)
b)清屏:
clrsrc(void)
c)显示字符:
drawtext(intx0,inty0,char*c,intpencolor)
d)触摸屏初始化:
INT_ADC_Enable(TRUE);
e)读取X:
intadc_x_position()
f)读取Y:
intadc_y_position()
2.编译程序
3.调试
五、实验报告要求:
1.试验程序流程图
2.带注解的程序清单
程序清单:
1.LCD编程主函数Main.C示例
voidC_Entry()
{
inti,j,k=0;
i=0;
Led4_On_or_Off(TRUE);
while(i++<1000000);
Led4_On_or_Off(FALSE);
clrsrc();
for(i=0;i<240;i++)
for(j=0;j<320;j++)
{
setpixel(j,j,0xff);
}
while(10);
;
}
intsetpixel(intx,inty,unsignedshortpencolor)
{
intmovetop;/*THEPIXELADDRESS*/
short*p;
if(x<0||x>(int)x_limit)returnERROR;
if(y<0||y>(int)y_limit)returnERROR;
/*指向所要显示的像素偏移地址*/
movetop=(x*x_size+y)*2;//一个像素占两个字节
p=(short*)(VideoAddrStart+movetop);
*p=pencolor;
return1;
}
voidclrsrc(void)
{
short*p;
for(p=(short*)VideoAddrStart;p<(short*)VideoAddrEnd;p++)*p=0;
return;
}
voidLed1_On_or_Off(intflag)
{
inttemp;
if(flag==TRUE)//led1on
{
//setGPF4
temp=rGPFCON;
rGPFCON=temp|(1<<8);
temp=rGPFDAT;
rGPFDAT=temp&(0<<4);
}
else//led1off
{
//setGPF4
temp=rGPFCON;
rGPFCON=temp|(1<<8);
temp=rGPFDAT;
rGPFDAT=temp|(1<<4);
}
}
voidLed2_On_or_Off(intflag)
{
inttemp;
if(flag==TRUE)//led1on
{
//setGPF4
temp=rGPFCON;
rGPFCON=temp|(1<<10);
temp=rGPFDAT;
rGPFDAT=temp&(0<<5);
}
else//led1off
{
//setGPF4
temp=rGPFCON;
rGPFCON=temp|(1<<10);
temp=rGPFDAT;
rGPFDAT=temp|(1<<5);
}
}
voidLed3_On_or_Off(intflag)
{
inttemp;
if(flag==TRUE)//led1on
{
//setGPF4
temp=rGPFCON;
rGPFCON=temp|(1<<12);
temp=rGPFDAT;
rGPFDAT=temp&(0<<6);
}
else//led1off
{
//setGPF4
temp=rGPFCON;
rGPFCON=temp|(1<<12);
temp=rGPFDAT;
rGPFDAT=t