这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » halibote523使用手记(从安装到程序编写)

共54条 4/6 |‹ 1 2 3 4 5 6 跳转至
专家
2010-10-17 22:27:24     打赏
31楼

程序1:查询方式::::::::::::::::::
LIN_UART_Syn.rar
#include "mb95200.h"

int ADVoltage=0x01;
void UART_chars(unsigned char cdata);
void UART_init (void)
{
 BGR1 = 0x00;  // Reloadvalue = 0d51 = 0x33 (500KHz, 9600Baud)
 BGR0 = 0x33;  // Reloadvalue = 0x33 = 0x00<<8 + 0x33 (500KHz, 9600Baud)
 SMR = 0x87;     // enable SOT, Reset, synchronous mode
 SSR = 0x00;     // clear flags, no interrupt
 ECCR_SSM = 1;    // have ST/STP bit
 SCR = 0xc3;     // enable transmit, Odd parity
}
char UART_readbyte (void)
{
 while (! SSR_RDRF);   // wait, until a byte is received
 return (RDR_TDR);    // return the received byte
}
void delay(unsigned int i)
{
   unsigned int m,n;
   for(m=0;m<i;m++)
     {
     for(n=0;n<6000;n++)
       {
       asm("\tNOP");
       }
     }
}
void UART_sendbyte (char ch)
{
 while (! SSR_TDRE);
 RDR_TDR = ch;     //transmit data     
}

void UARTPut(const char *data,unsigned char len)
{
    unsigned char i;
    for(i=0; i<len; i++) UART_sendbyte(data[i]);
}
void UART_chars(unsigned char cdata)
{
    unsigned char i;
    i=cdata>>4;
    if(i>=0 && i<=9) UART_sendbyte(i+0x30);
    else             UART_sendbyte(i+0x37);
    i=cdata & 0x0F;
    if(i>=0 && i<=9) UART_sendbyte(i+0x30);
    else             UART_sendbyte(i+0x37);
}
void InitADC(void)                         
{                                                   
    ADC2 = 0x81;                // 8-bit resolution, enable interrupts
    ADC1 = 0x01;                // AN0 pin as input, start AD
}

void AD_Sample (void)
{  
    ADVoltage=ADD_ADDL;                           
    ADC1=0x01;
    //ADC2 = 0x81;                         
}
/******************************************************************************
NAME : main ()
FUNCTION: synchronously transmit a byte or receive a byte
******************************************************************************/
void main (void)
{
 //unsigned char rec_data = 0;
   DDR0_P00 = 0;        //P00 intput
   //DDR0_P05 = 1;         //P05 output
   //DDR0_P06 = 0;        //P06 input
   DDR0_P03 = 1;        //P03 output
   DDR0_P04 = 0;        //P04 input
   AIDRL = 0xfe;       //Port input enabled
   PDR0_P00 = 0x00; 
   //PDR0_P05 = 0x01; 

   UART_init ();
   InitIrqLevels();            // initialise Interrupt level register and IRQ vector table
    __EI();                     // global interrupt enable 
    //__set_il(3);                // set global interrupt mask to allow all IRQ levels  
    InitADC();                  // init AD - converte
    while (1)
   {
  asm("\tNOP");
  //UART_sendbyte(0xaa);
  delay(10);
  UARTPut("ADVal:",7);
  //DDR0_P00 = 0;
  //delay(1);
  AD_Sample();
  UART_chars(ADVoltage);
  UARTPut("\n",2);
  //rec_data = UART_readbyte ();
  asm("\tNOP");
  asm("\tNOP");
   }    
}


专家
2010-10-17 22:31:00     打赏
32楼
转换的值为:
AD的引脚接到地线时:采集的电压是:(00~=0V)


AD引脚悬空的采集电压是:(96~=2.94V)





专家
2010-10-17 22:36:04     打赏
33楼

程序2:中断方式::::::::::::::::::
#include "mb95200.h"

int ADVoltage=0x01;
void UART_chars(unsigned char cdata);
void UART_init (void)
{
 BGR1 = 0x00;  // Reloadvalue = 0d51 = 0x33 (500KHz, 9600Baud)
 BGR0 = 0x33;  // Reloadvalue = 0x33 = 0x00<<8 + 0x33 (500KHz, 9600Baud)
 SMR = 0x87;     // enable SOT, Reset, synchronous mode
 SSR = 0x00;     // clear flags, no interrupt
 ECCR_SSM = 1;    // have ST/STP bit
 SCR = 0xc3;     // enable transmit, Odd parity
}
char UART_readbyte (void)
{
 while (! SSR_RDRF);   // wait, until a byte is received
 return (RDR_TDR);    // return the received byte
}
void delay(unsigned int i)
{
   unsigned int m,n;
   for(m=0;m<i;m++)
     {
     for(n=0;n<6000;n++)
       {
       asm("\tNOP");
       }
     }
}
void UART_sendbyte (char ch)
{
 while (! SSR_TDRE);
 RDR_TDR = ch;     //transmit data     
}

void UARTPut(const char *data,unsigned char len)
{
    unsigned char i;
    for(i=0; i<len; i++) UART_sendbyte(data[i]);
}
void UART_chars(unsigned char cdata)
{
    unsigned char i;
    i=cdata>>4;
    if(i>=0 && i<=9) UART_sendbyte(i+0x30);
    else             UART_sendbyte(i+0x37);
    i=cdata & 0x0F;
    if(i>=0 && i<=9) UART_sendbyte(i+0x30);
    else             UART_sendbyte(i+0x37);
}
void InitADC(void)                         
{                                                   
    ADC2 = 0x81;                // 8-bit resolution, enable interrupts
    ADC1 = 0x01;                // AN0 pin as input, start AD
}
__interrupt void ISR_ADC (void)
{   
    ADVoltage=ADD_ADDL;                            // voltage calculating
    ADC1=0x01;                           // clear interrupt flag, start AD again
}

/******************************************************************************
NAME : main ()
FUNCTION: synchronously transmit a byte or receive a byte
******************************************************************************/
void main (void)
{
 //unsigned char rec_data = 0;
   DDR0_P00 = 0;        //P00 intput
   //DDR0_P05 = 1;         //P05 output
   //DDR0_P06 = 0;        //P06 input
   DDR0_P03 = 1;        //P03 output
   DDR0_P04 = 0;        //P04 input
   AIDRL = 0xfe;       //Port input enabled
   PDR0_P00 = 0x00; 
   //PDR0_P05 = 0x01; 

   UART_init ();
   InitIrqLevels();            // initialise Interrupt level register and IRQ vector table
    __EI();                     // global interrupt enable  
    __set_il(3);                // set global interrupt mask to allow all IRQ levels  
    InitADC();                  // init AD - converte
    while (1)
   {
  asm("\tNOP");
  //UART_sendbyte(0xaa);
  delay(10);
  UARTPut("ADVal:",7);
  //DDR0_P00 = 0;
  //delay(1);
  UART_chars(ADVoltage);
  UARTPut("\n",2);
  asm("\tNOP");
  asm("\tNOP");
   }    
}

在Vector文件::
1、ILR4 = 0xDF; 
。。。。。。。
2、
__interrupt void DefaultIRQHandler (void);
__interrupt void ISR_ADC (void);
。。。。。。。。。。。。。。。。。。
3、
修改:#pragma intvect ISR_ADC 18

专家
2010-10-18 09:18:11     打赏
34楼
应用的场合不一样,书写程序的方法也不一样!!不在于中断或者是查询,在于能够对AD转换器原理的理解

专家
2010-10-18 19:21:22     打赏
35楼
外部中断测试:
中断请求号  中断级设置寄存器  中断源
IRQ0             L00【1:0】           外部中断ch4
IRQ1             L01【1:0】           外部中断ch5
IRQ2             L02【1:0】           外部中断ch2、ch6
IRQ3             L03【1:0】           外部中断ch7

外部中断电路0注意事项:
1、边缘极性选择位SL值位过程中,使中断请求位EIE清0(禁止中断请求),设定边缘极性后,外部中断请求标志位EIR清0
2、若外部中断请求标志位置1,且使能中断中断请求使能位,操作不能从中断服务例程中回复,必须始终清理中断服务例程中的外部中断请求使能位

专家
2010-10-18 19:24:29     打赏
36楼
程序要求:发生中断时候,每隔2秒的时间UART输出:Initerrupt, 没有中断时输出:NO Initerr
例程如下:INITTest.rar
现象如下:

专家
2010-10-18 19:29:43     打赏
37楼
至此:应用手记已经基本完成,手记包含了:
1、编译环境的安装
2、调试器烧写程序以及驱动的安装
3、从新建文件到详细的设置步骤
4、IO口操作调试(LED操作)
5、定时器调试(点亮与熄灭LED)
6、LIN-UART调试
7、AD转换器的调试
8、外部中断的调试
希望这些手记能带给朋友们一点点的帮助,下次总结一下容易出错的问题以及解决方法!!

专家
2010-10-19 11:07:47     打赏
38楼

专家
2010-10-21 09:10:24     打赏
39楼
系统时钟图::

专家
2010-10-27 10:42:36     打赏
40楼

中断向量解释:
例如:
ILR0 = 0xCF;      //  IRQ0:  external interrupt  ch4        --> 01
                      //  IRQ1:  external interrupt  ch5        --> 01
                      //  IRQ2:  external interrupt ch2 | ch6   --> 01
                      //  IRQ3:  external interrupt ch3 | ch7   --> 01

ILRx(x=0-5),每个x里面包含有四个中断,每个中断占用两位
CF=11 00 11 11
那么表示的是:
11:--IRQ3
00:--IRQ2
11:--IRQ1
11:--IRQ0
即高位表示的是后面的中断,地位表示的是最开始的中断
优先级可以设置为0-3级
优先级:ILR0>ILR5,同一级里面,设置的数值越小,那么优先级就越大,也就是00>11


共54条 4/6 |‹ 1 2 3 4 5 6 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]