资源描述
中南林业科技大学
课程名称:ARM嵌入式课程设计
学 院:计算机和信息工程学院
专业班级:电子信息工程一班
设计者:
学号:
目 录
一、课程设计题目及其要求: 3
二、设计方案分析: 4
三、参考文件: 5
四、总体步骤设计图: 5
五、设计步骤图以下 6
六、生产控制软件 7
1、定时器 7
2、A/D转换 7
3、LCDYM12864I液晶显示模块 8
七、小组体会 11
八、附录 12
一、课程设计题目及其要求:
某化学反应过程装置以下图,它由4个容器组成,容器之间用泵连接,以此进行化学反应。每个容器全部有检测容器空和满传感器,2#容器还有加热器和温度传感器,3#容器还有搅拌器。
化学反应步骤以下:
按开启按钮后,1#、2#容器分别用泵P1、P2抽入碱和聚合物,抽满后各自传感器发出信号,P1、P2关闭。2#容器在P2开启后10s开始开启加热器,当2#容器中聚合物加热到60℃时,温度传感器发出信号,关闭加热器。
当加热器关闭后,P3和P4开启,分别将1#、2#容器中溶液送到3#反应器中,同时开启搅拌器,当3#满或1#、2#空,则P3、P4停止,P3、P4停止后搅拌器继续搅拌60s后,P5开启将混合液抽到产品池4#容器,直到4#满或3#空。成品将用P6抽走。
为了提升生产效率,假如4#池没有满,当P3关闭时P1开启;P4关闭时P2开启,使1#、2#和3#并行工作。
当按下停止按钮后,应该完成一个完整生产步骤,即把1#、2#容器中反应物用完,把3#容器全部混合液抽闲到4#池,最终1#、2#、3#池处于空状态,然后才停止全部工作。
综合题目设计要求,因为只需要用程序来控制反应步骤,所以P1、P2、P3、P4、P5、P6和加热器、搅拌器全部用LED灯来相同替换,LED亮则表示开启,灭则表示关闭。用按键来表示容器传感器和开始键,按键按下则表示容器已满,反之则没有满。
二、设计方案分析:
当该化学反应装置开始键S1按下时,LED1和LED2开始点亮,表明开始向容器1和容器2开始分别注入碱和聚合物。和此同时在经过定时器10秒定时后工作容器2加热器开始工作,当容器1和容器2满状态时,由各自传感器即按键S2和S3按下,表明容器已满,则P1和P2停止工作即LED1和LED2同时熄灭。在开始注入液体时容器2中相对应代表加热器工作LED3开始点亮,因为容器2内有温度传感器,所以能够经过A/D转换把对应温度模拟量转换成数字量,假如温度超出60摄氏度, P3和P4代表LED4和LED5开始点亮,搅拌器对应LED6也开始工作即点亮。把容器1和容器2液体装入容器3反应池中。当容器3满以后,P3和P4停止工作,即LED4和LED5熄灭,经过定时器0定时60秒来控制搅拌器工作即LED6再点亮60秒。以后待反应充足后把液体装入容器4中即LED7点亮,P5工作。当容器4中液体装满即按键S5按下时,使P6开始工作即LED8开始点亮,假如容器4中液体未满时,将返回到刚开始状态继续注入液体使得继续工作。
三、参考文件:
1)周立功主编,ARM嵌入式系统基础教程,北京航空航天大学出版社,.9
2)开发板电路图,Y1_LPC 229X_V30.pdf
四、总体步骤设计图:
LED3和LED6控制加热器和A/D转换器
LED3熄灭
五 、设计步骤图以下
各个模块对应关系以下:
LED1—P1 按键S1—装置开始键
按键S5—#4满传感器
按键S3—#2满传感器
按键S4—#3满传感器
按键S2—#1满传感器
LED7—P5
LED2—P2
LED3—加热器
LED4—P3
LED5—P4
LED6—搅拌器
LED8—P6
六、生产控制软件:
1、定时器:
定时器0和1初始化工作:
T0TC=0;
T1TC=0;
T0PR=0;
T1PR=0;
T0MCR=0X03;
T1MCR=0X03;
T0MR0=Fpclk/5;
T1MR0=Fpclk/5;
VICIntSelect=VICIntSelect&(~(3<<4;
VICVectCntl0=0x20|4;
VICVectCntl1=0x20|5;
VICVectAddr0=(uinttimer0_isr;
VICVectAddr1=(uinttimer1_isr;
T0IR|=0x01;
T1IR|=0x01;
VICIntEnable|=(3<<4;
2、A/D转换:
初始化工作程序以下:
void ADC_Init( void
{
ADCR = ( 1 << 0 | // SEL = 1 ,选择通道0
( ( Fpclk /1000000 - 1 << 8 | // CLKDIV = Fpclk / 1000000 - 1 ,即转换时钟为1MHz
( 0 << 16 | // BURST = 0 ,软件控制转换操作
( 0 << 17 | // CLKS = 0 ,使用11clock转换
( 1 << 21 | // PDN = 1 , 正常工作模式(非掉电转换模式
( 0 << 22 | // TEST1:0 = 00 ,正常工作模式(非测试模式
( 0 << 27 ; // EDGE = 0 (CAP/MAT引脚下降沿触发ADC转换
VICIntEnable&=~(1<<18;
}
3、LCDYM12864I液晶显示模块:
程序以下:
void Lcd_Command_Left( U8 a
{
while ( ( Lcd_Left_Status_Read & 0x80 == 0x80 ;//busy wait
Lcd_Left_Command_Write = a; //write command byte
}
void Lcd_Command_Right( U8 a
{
while ( ( Lcd_Right_Status_Read & 0x80 == 0x80 ;//busy wait
Lcd_Right_Command_Write = a; //write command byte
}
void Lcd_Data_Left_WR( U8 a
{
while ( ( Lcd_Left_Status_Read & 0x80 == 0x80 ;//busy wait
Lcd_Left_Data_Write = a; //write data
}
void Lcd_Data_Right_WR( U8 a
{
while ( ( Lcd_Right_Status_Read & 0x80 == 0x80 ; //busy wait
Lcd_Right_Data_Write = a; //write data
}
void Lcd_Clear( void
{
U8 a, b;
for ( a = 0; a < 8; a++ //Clear RAM space of display
{
Lcd_Command_Left( 0xb8 | a ; //Set row address of the left half in display area
Lcd_Command_Right( 0xb8 | a ; //Set row address of the left half in display area
Lcd_Command_Left( 0x40 ; //Set tier address of the left half in display area
Lcd_Command_Right( 0x40 ; //Set tier address of the left half in display area
b = 64;
while ( b
{
Lcd_Data_Left_WR( 0x00 ; //Write 0 on the left half of display area
Lcd_Data_Right_WR( 0x00 ; //Write 0 on the right half of display area.
b = b - 1;
}
}
}
void Lcd_Init( void
{
int timeout=30000; //overtime control
Lcd_Command_Left( 0xC0 ; //Set the start row address on the left half
Lcd_Command_Right( 0xC0 ; //Set the start row address on the right half
do
{
Lcd_Command_Left( 0x3F ;
timeout--;
}
while ( (( Lcd_Left_Status_Read & 0x20 == 0x20 && (timeout!=0 ;//if display and overtiem is not,wait
timeout=30000;
do
{
Lcd_Command_Right( 0x3F ;//Open the left and right half of display area.
timeout--;
}
while ( (( Lcd_Right_Status_Read & 0x20 == 0x20 && (timeout!=0 ;//if display and overtiem is not,wait
}
void Lcd_Display_s( U8* S,uint x,uint y
{
U8 a, b; U32 c = 0;
if(y<8
for ( a = 2*x; a < 2*x+2; a++
{
Lcd_Command_Left( 0xb8 | a ;
Lcd_Command_Left( 0x40+ 8*y ;
for ( b = 0; b < 8; b++
{
Lcd_Data_Left_WR( S[c] ;c = c + 1;
}
}
else
for ( a = 2*x; a < 2*x+2; a++
{
Lcd_Command_Right( 0xb8 | a ;
Lcd_Command_Right( 0x40+8*(y-8 ;
for ( b = 0; b < 8; b++
{
Lcd_Data_Right_WR( S[c] ;c = c + 1;
}
}
}
void Lcd_Display_c( U8* S,uint x,uint y
{
U8 a, b; U32 c = 0;
if(y<4
for ( a = 2*x; a < 2*x+2; a++
{
Lcd_Command_Left( 0xb8 | a ;
Lcd_Command_Left( 0x40+ 16*y ;
for ( b = 0; b < 16; b++
{
Lcd_Data_Left_WR( S[c] ;c = c + 1;
}
}
else
for ( a = 2*x; a < 2*x+2; a++
{
Lcd_Command_Right( 0xb8 | a ;
Lcd_Command_Right( 0x40+16*(y-4 ;
for ( b = 0; b < 16; b++
{
Lcd_Data_Right_WR( S[c] ;c = c + 1;
}
}
}
void Lcd_YM12864_Init( void
{
Lcd_Init(; //LCD Init
Lcd_Clear(; //Clear screen
}
七、小组体会:
对于大多数嵌入式初学者来说,要想学好嵌入式,学习和ARM相关知识是很有必需,比如ARM接口技术,然后掌控ARM研发工具Keil,学会使用仿真器,写些接口方面代码。其实,ARM研发工具是初学者最应该花时间掌握,这好比马车前进轮子!这段时间大约需要2个月,因为ARM设计东西太多了,开发工具也比通常单片机复杂。
在学习ARM初级阶段,购置部分相关书籍是少不了,因为好书籍通常全部比较系统,这对于自己系统掌握ARM来说是很关键。系统掌控好ARM接口知识后,接着再进行bootloader学习,如uboot移植连同系统移植等,这时因为之前已经有了ARM接口方面知识,所以uboot学习及移植就会很快了。
相关bootloader学习,应该算是ARM里面初学者最难突破步骤,不过这又是必需(个人认为),因为这是掌握ARM底层原理最好方法!
接着我们能够再移植kernel、制作自己文档系统。这些全部做好后,嵌入式研发环境就搭好了。下面就能够学习Linux系统编程及Linux驱动研发了。接口基础会帮助我们更轻易了解驱动原理。同时,我们能够选择一个kernel里已支持且您比较熟悉接口驱动如RTC等,进行分析和学习,并尝试进行修改或照着自己编写。根据这么步骤下来能够少走少许弯路,快速入门,而且以一个比较合理步骤进行学习。
八、附录
#include "LPC2294.H"
#include "def.h"
#include "config.h"
#include "LCD_YM12864I.h"
#define uint unsigned int
#define uchar unsigned char
#define pump1 0x00000004
#define pump2 0x00000010
#define pump3 0x00000020
#define pump4 0x00000040
#define pump5 0x10000000
#define pump6 0x0000
#define jiare 0x40000000
#define jiaoban 0x80000000
#define open 0x00010000
#define close 0x0000
#define binf1 0x00040000
#define bine1 0x00080000
#define binf2 0x00100000
#define bine2 0x0000
#define binf3 0x00400000
#define bine3 0x40000000
uint count=0,sec=0,ms=0,miao=0;
uchar temp,e=0;
uchar s[][32]={
{0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,
0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00,},
{0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,
0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,},
{0x10,0x10,0x10,0xFF,0x10,0x10,0x50,0x20,0xD8,0x17,0x10,0x10,0xF0,0x10,0x10,0x00,
0x00,0x7F,0x21,0x21,0x21,0x7F,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00,},
{0x00,0xFE,0x02,0x22,0xDA,0x06,0x10,0xD2,0x56,0x5A,0x53,0x5A,0x56,0xD2,0x10,0x00,
0x00,0xFF,0x08,0x10,0x08,0x07,0x10,0x17,0x15,0x15,0xFD,0x15,0x15,0x17,0x10,0x00,},
};
uchar d[][16]={
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,},
{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,},
{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,},
{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,},
{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,},
{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,},
{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,},
{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,},
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,},
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,},
{0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,}
};
void Lcd_Command_Left( U8 a
{
while ( ( Lcd_Left_Status_Read & 0x80 == 0x80 ;//busy wait
Lcd_Left_Command_Write = a; //write command byte
}
void Lcd_Command_Right( U8 a
{
while ( ( Lcd_Right_Status_Read & 0x80 == 0x80 ;//busy wait
Lcd_Right_Command_Write = a; //write command byte
}
void Lcd_Data_Left_WR( U8 a
{
while ( ( Lcd_Left_Status_Read & 0x80 == 0x80 ;//busy wait
Lcd_Left_Data_Write = a; //write data
}
void Lcd_Data_Right_WR( U8 a
{
while ( ( Lcd_Right_Status_Read & 0x80 == 0x80 ; //busy wait
Lcd_Right_Data_Write = a; //write data
}
void Lcd_Clear( void
{
U8 a, b;
for ( a = 0; a < 8; a++ //Clear RAM space of display
{
Lcd_Command_Left( 0xb8 | a ; //Set row address of the left half in display area
Lcd_Command_Right( 0xb8 | a ; //Set row address of the left half in display area
Lcd_Command_Left( 0x40 ; //Set tier address of the left half in display area
Lcd_Command_Right( 0x40 ; //Set tier address of the left half in display area
b = 64;
while ( b
{
Lcd_Data_Left_WR( 0x00 ; //Write 0 on the left half of display area
Lcd_Data_Right_WR( 0x00 ; //Write 0 on the right half of display area.
b = b - 1;
}
}
}
void Lcd_Init( void
{
int timeout=30000; //overtime control
Lcd_Command_Left( 0xC0 ; //Set the start row address on the left half
Lcd_Command_Right( 0xC0 ; //Set the start row address on the right half
do
{
Lcd_Command_Left( 0x3F ;
timeout--;
}
while ( (( Lcd_Left_Status_Read & 0x20 == 0x20 && (timeout!=0 ;//if display and overtiem is not,wait
timeout=30000;
do
{
Lcd_Command_Right( 0x3F ;//Open the left and right half of display area.
timeout--;
}
while ( (( Lcd_Right_Status_Read & 0x20 == 0x20 && (timeout!=0 ;//if display and overtiem is not,wait
}
void Lcd_Display_s( U8* S,uint x,uint y
{
U8 a, b; U32 c = 0;
if(y<8
for ( a = 2*x; a < 2*x+2; a++
{
Lcd_Command_Left( 0xb8 | a ;
Lcd_Command_Left( 0x40+ 8*y ;
for ( b = 0; b < 8; b++
{
Lcd_Data_Left_WR( S[c] ;c = c + 1;
}
}
else
for ( a = 2*x; a < 2*x+2; a++
{
Lcd_Command_Right( 0xb8 | a ;
Lcd_Command_Right( 0x40+8*(y-8 ;
for ( b = 0; b < 8; b++
{
Lcd_Data_Right_WR( S[c] ;c = c + 1;
}
}
}
void Lcd_Display_c( U8* S,uint x,uint y
{
U8 a, b; U32 c = 0;
if(y<4
for ( a = 2*x; a < 2*x+2; a++
{
Lcd_Command_Left( 0xb8 | a ;
Lcd_Command_Left( 0x40+ 16*y ;
for ( b = 0; b < 16; b++
{
Lcd_Data_Left_WR( S[c] ;c = c + 1;
}
}
else
for ( a = 2*x; a < 2*x+2; a++
{
Lcd_Command_Right( 0xb8 | a ;
Lcd_Command_Right( 0x40+16*(y-4 ;
for ( b = 0; b < 16; b++
{
Lcd_Data_Right_WR( S[c] ;c = c + 1;
}
}
}
void Lcd_YM12864_Init( void
{
Lcd_Init(; //LCD Init
Lcd_Clear(; //Clear screen
}
void ADC_Init( void
{
ADCR = ( 1 << 0 | // SEL = 1 ,选择通道0
( ( Fpclk /1000000 - 1 << 8 | // CLKDIV = Fpclk / 1000000 - 1 ,即转换时钟为1MHz
( 0 << 16 | // BURST = 0 ,软件控制转换操作
( 0 << 17 | // CLKS = 0 ,使用11clock转换
( 1 << 21 | // PDN = 1 , 正常工作模式(非掉电转换模式
( 0 << 22 | // TEST1:0 = 00 ,正常工作模式(非测试模式
( 0 << 27 ; // EDGE = 0 (CAP/MAT引脚下降沿触发ADC转换
VICIntEnable&=~(1<<18;
}
uint Read_Adc( void
{
U32 ADC_Data;
ADCR = ADCR | ( 1 << 24 ; // 启运转换
while ( ( ADDR & 0x80000000 == 0 ;
ADC_Data = ADDR; // 读取ADC结果
ADC_Data = ( ADC_Data >> 6 & 0x3FF;
return ADC_Data ; //返回AD转换值
}
void __irq timer0_isr(void
{
count++;
if(count==20
{ count=0;sec++;}
T0IR|=0x01;
VICVectAddr=0x00;
}
void __irq timer1_isr(void
{
ms++;
if(ms==20
{ ms=0;miao++;}
T1IR|=0x01;
VICVectAddr=0x00;
}
void PortInit( void
{
PINSEL0 = ( 0x5555 << 16 | ( 0x0005 ; // 设置P0.0--P0.15引脚功效
IO0DIR = ( 0x00 << 24 | ( 0x28 << 16 | ( 0x00 << 8 | ( 0x75 ; // 设置P0引脚方向
PINSEL1 = ( 0x0545 << 16 | ( 0x0400 ; // 设置P0.16--P0.31引脚功效
PINSEL2 = ( 0xf << 24 | ( 0x81 << 16 | ( 0x69 << 8 | ( 0x14 ; // 设置P1-P2-P3引脚功效
IO1DIR = ( 0x01 << 24 | ( 0xe6 << 16 | ( 0x00 << 8 | ( 0x00 |(1<<23 ; // 设置P1引脚方向
IO2DIR = ( 0xf8 << 24 | ( 0x00 << 16 | ( 0x00 << 8 | ( 0x00 ; // 设置P2引脚方向
IO3DIR = ( 0x00 << 24 | ( 0x00 << 16 | ( 0x00 << 8 | ( 0x00 ; // 设置P3引脚方向
}
main(
{
uchar flag;
PortInit(;
IO0SET=0x00000074;
IO2SET=0xF0000000;
IO1SET=(1<<23;
ADC_Init(;
Lcd_YM12864_Init(;
T0TC=0;
T1TC=0;
T0PR=0;
T1PR=0;
T0MCR=0X03;
T1MCR=0X03;
T0MR0=Fpclk/5;
T1MR0=Fpclk/5;
VICIntSelect=VICIntSelect&(~(3<<4;
VICVectCntl0=0x20|4;
VICVectCntl1=0x20|5;
VICVectAddr0=(uinttimer0_isr;
VICVectAddr1=(uinttimer1_isr;
T0IR|=0x01;
T1IR|=0x01;
VICIntEnable|=(3<<4;
while(1
{
while(1
{
if((IO2PIN&open==0
{
flag=0;
Lcd_Display_c(s[0],0,1;
Lcd_Display_c(s[1],0,2;
Lcd_Display_s(d[10],0,7;
Lcd_Display_c(s[2],1,1;
Lcd_Display_c(s[3],1,2;
Lcd_Display_s(d[10],1,7;
break;
}
}
IO0CLR=pump1;
T1TCR=0X01;
IO0CLR=pump2;
while(1
{
T0TCR=0X01;
while(sec<10
{
if((IO2PIN&binf1==0
{
IO0SET=pump1;
miao=0;
T1TCR=0X02;
}
if((IO2PIN&binf2==0 IO0SET=pump2;
if((IO2PIN&close==0 flag=1;
if(miao>120
{
e=1;
Lcd_Display_s(d[e],1,11;
}
}
sec=0;
IO2CLR=jiare;
T0TCR=0X01;
while(temp<60 // ad
{
if((IO2PIN&binf1==0
{
IO0SET=pump1;
miao=0;
T1TCR=0X02;
}
if((IO2PIN&binf2==0 IO0SET=pump2;
if((IO2PIN&close==0 flag=1;
if(miao>120
{
e=1;
Lcd_Display_s(d[e],1,11;
}
if(sec>180
{
e=3;
Lcd_Display_s(d[e],3,11;
}
temp=Read_Adc(;
Lcd_Display_s(d[temp/10],0,10;
Lcd_Display_s(d[temp%10],0,11;
}
temp=0;
IO2SET=jiare;
IO0CLR=pump3;
IO0CLR=pump4;
IO2CLR=jiaoban;
sec=0;
while((IO2PIN&bine1!=0&&(IO2PIN&bine2!=0&&(IO2PIN&binf3!=0
{
if((IO2PIN&binf1==0
{
IO0SET=pump1;
miao=0;
T1TCR=0X02;
}
if((IO2PIN&binf2==0 IO0SET=pump2;
if((IO2PIN&close==0 flag=1;
if(miao>120
{
e=1;
Lcd_Display_s(d[e],1,11;
}
if(sec>120
{
e=2;
Lcd_Display_s(d[e],2,11;
}
}
T0TCR=0X02;
sec=0;
IO0SET=pump3;
IO0SET=pump4;
if(flag==0
{
if((IO2PIN&binf1!=0
{
IO0CLR=pump1;
T1TCR=0X01;
}
if((IO2PIN&binf2!=0
IO0CLR=pump2;
}
T0TCR=0X01;
while(sec<60
{
if((IO2PIN&binf1==0
{
IO0SET=pump1;
miao=0;
T1TCR=0X02;
}
if((IO2PIN&binf2==0 IO0SET=pump2;
if((IO2PIN&close==0 flag=1;
if(miao>120
{
e=1;
Lcd_Display_s(d[e],1,11;
}
}
sec=0;
IO2SET=jiaoban;
IO2CLR=pump5;
while((IO0PIN&bine3!=0
{
if((IO2PIN&binf1==0
{
IO0SET=pump1;
miao=0;
T1TCR=0X02;
}
if((IO2PIN&binf2==0 IO0SET=pump2;
if((IO2PIN&close==0 flag=1;
if(miao>120
{
e=1;
Lcd_Display_s(d[e],1,11;
}
if(sec>180
{
e=4;
Lcd_Display_s(d[e],1,14;
}
}
T0TCR=0X02;
sec=0;
IO2SET=pump5;
IO2CLR=pump6;
if(flag==1
if((IO2PIN&bine1==0&&(IO2PIN&bine2==0&&(IO0PIN&bine3==0
{
IO2SET=pump6;
IO0SET=pump1;
IO0SET=pump2;
Lcd_Clear(;
break;
}
}
}
}
展开阅读全文