这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 电子DIY » wenyangzeng ARM DIY进程贴 红外解码

共107条 10/11 |‹ 6 7 8 9 10 11 跳转至
工程师
2012-05-31 20:45:32     打赏
91楼

部分代码
void main(void)
{
    #if (OS_TASK_NAME_SIZE > 14) && (OS_TASK_STAT_EN > 0)
    INT8U  err;
    #endif
   
    OSInit();
   LcdInit();
   TestLCDS();
    //设置空闲任务名称
    #if OS_TASK_NAME_SIZE > 14
    OSTaskNameSet(OS_TASK_IDLE_PRIO, "uC/OS-II Idle", &err);
    #endif
    //设置统计任务名称
    #if (OS_TASK_NAME_SIZE > 14) && (OS_TASK_STAT_EN > 0)
    OSTaskNameSet(OS_TASK_STAT_PRIO, "uC/OS-II Stat", &err);
    #endif
   
    //用任务建立任务
    OSTaskCreateExt(APP_TaskStart,                                //void (*task)(void *pd) 任务首地址
                    (void *)0,                                            //void *pdata            数据指针
                    &APP_TaskStartStk[APP_TASK_START_STK_SIZE - 1],       //OS_STK *ptos           指向任务堆栈栈顶的指针
                    (INT8U)APP_TASK_START_PRIO,        //INT8U prio             任务优先级
                    (INT16U)APP_TASK_START_ID,            //INT16U id              任务的ID号
                    &APP_TaskStartStk[0],                               //OS_STK *pbos           指向任务堆栈栈底的指针
                    (INT32U)APP_TASK_START_STK_SIZE,     //INT32U stk_size        堆栈容量
                    (void *)0,                                            //void *pnext            数据指针
                    OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);     //INT16U opt             设定OSTaskCreateExt的选项

    #if OS_TASK_NAME_SIZE > 14
    OSTaskNameSet(APP_TASK_START_PRIO, "Task-Start", &err);
    #endif

   
    OSStart();
}
static void Task1_LED1(void *pdata)
{
    pdata = pdata;
    while(1)
    {
        GPIO_ResetBits(GPIOE, GPIO_Pin_5);
        byte_disp(7,3,'1');            //补丁
        OSTimeDly(OS_TICKS_PER_SEC * 2);
        GPIO_SetBits(GPIOE, GPIO_Pin_5);
        byte_disp(7,3,'0');         //补丁
        OSTimeDly(OS_TICKS_PER_SEC * 2);
       
    }
}
static void  Task2_LED2(void *pdata)
{
    pdata = pdata;
    while(1)
    {
        GPIO_ResetBits(GPIOE, GPIO_Pin_4);
        byte_disp(7,7,'1');         //补丁
        OSTimeDly(OS_TICKS_PER_SEC / 1);
        GPIO_SetBits(GPIOE, GPIO_Pin_4);
        byte_disp(7,7,'0');         //补丁
        OSTimeDly(OS_TICKS_PER_SEC / 1);
  
    }
}
static void  Task3_LED3(void *pdata)
{
    pdata = pdata;
    while(1)
    {
        GPIO_ResetBits(GPIOE, GPIO_Pin_3);
        byte_disp(7,11,'1');       //补丁
        OSTimeDly(OS_TICKS_PER_SEC / 2);
        GPIO_SetBits(GPIOE, GPIO_Pin_3);
        byte_disp(7,11,'0');        //补丁
        OSTimeDly(OS_TICKS_PER_SEC / 2);
       
    }
}
static void  Task4_LED4(void *pdata)
{
    pdata = pdata;
    while(1)
    {
        GPIO_ResetBits(GPIOE, GPIO_Pin_2);
        byte_disp(7,15,'1');         //补丁
        OSTimeDly(OS_TICKS_PER_SEC / 4);
        GPIO_SetBits(GPIOE, GPIO_Pin_2);
        byte_disp(7,15,'0');        //补丁
        OSTimeDly(OS_TICKS_PER_SEC / 4);
    }
}

//bsp.c(补丁部分)
static  void  BSP_LED_Init (void)
{
    GPIO_InitTypeDef  gpio_init;


    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);

    gpio_init.GPIO_Pin   = BSP_GPIOE_LED1 | BSP_GPIOE_LED2 | BSP_GPIOE_LED3 | BSP_GPIOE_LED4;
    gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
    gpio_init.GPIO_Mode  = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOE, &gpio_init);
}

/*
*********************************************************************************************************
*                                             BSP_LED_On()
*
* Description : Turn ON any or all the LEDs on the board.
*
* Argument(s) : led     The ID of the LED to control:
*
*                       0    turn ON all LEDs on the board
*                       1    turn ON LED 1
*                       2    turn ON LED 2
*                       3    turn ON LED 3
*                       4    turn ON LED 4
*
* Return(s)   : none.
*
* Caller(s)   : Application.
*
* Note(s)     : none.
*********************************************************************************************************
*/

void  BSP_LED_On (CPU_INT08U led)
{
    switch (led) {
        case 0:
             GPIO_SetBits(GPIOE, BSP_GPIOE_LED1 | BSP_GPIOE_LED2 | BSP_GPIOE_LED3 | BSP_GPIOE_LED4);
             break;

        case 1:
             GPIO_SetBits(GPIOE, BSP_GPIOE_LED1);
             break;

        case 2:
             GPIO_SetBits(GPIOE, BSP_GPIOE_LED2);
             break;

        case 3:
             GPIO_SetBits(GPIOE, BSP_GPIOE_LED3);
             break;

        case 4:
             GPIO_SetBits(GPIOE, BSP_GPIOE_LED4);
             break;

        default:
             break;
    }
}

/*
*********************************************************************************************************
*                                              BSP_LED_Off()
*
* Description : Turn OFF any or all the LEDs on the board.
*
* Argument(s) : led     The ID of the LED to control:
*
*                       0    turn OFF all LEDs on the board
*                       1    turn OFF LED 1
*                       2    turn OFF LED 2
*                       3    turn OFF LED 3
*                       4    turn OFF LED 4
*
* Return(s)   : none.
*
* Caller(s)   : Application.
*
* Note(s)     : none.
*********************************************************************************************************
*/

void  BSP_LED_Off (CPU_INT08U led)
{
    switch (led) {
        case 0:
             GPIO_ResetBits(GPIOE, BSP_GPIOE_LED1 | BSP_GPIOE_LED2 | BSP_GPIOE_LED3 | BSP_GPIOE_LED4);
             break;

        case 1:
             GPIO_ResetBits(GPIOE, BSP_GPIOE_LED1);
             break;

        case 2:
             GPIO_ResetBits(GPIOE, BSP_GPIOE_LED2);
             break;

        case 3:
             GPIO_ResetBits(GPIOE, BSP_GPIOE_LED3);
             break;

        case 4:
             GPIO_ResetBits(GPIOE, BSP_GPIOE_LED4);
             break;

        default:
             break;
    }
}

/*
*********************************************************************************************************
*                                            BSP_LED_Toggle()
*
* Description : TOGGLE any or all the LEDs on the board.
*
* Argument(s) : led     The ID of the LED to control:
*
*                       0    TOGGLE all LEDs on the board
*                       1    TOGGLE LED 1
*                       2    TOGGLE LED 2
*                       3    TOGGLE LED 3
*                       4    TOGGLE LED 4
*
* Return(s)   : none.
*
* Caller(s)   : Application.
*
* Note(s)     : none.
*********************************************************************************************************
*/

void  BSP_LED_Toggle (CPU_INT08U led)
{
    CPU_INT32U  pins;


    pins = GPIO_ReadOutputData(GPIOE);

    switch (led) {
        case 0:
             BSP_LED_Toggle(1);
             BSP_LED_Toggle(2);
             BSP_LED_Toggle(3);
             BSP_LED_Toggle(4);
             break;

        case 1:
             if ((pins & BSP_GPIOE_LED1) == 0) {
                 GPIO_SetBits(  GPIOE, BSP_GPIOE_LED1);
             } else {
                 GPIO_ResetBits(GPIOE, BSP_GPIOE_LED1);
             }
            break;

        case 2:
             if ((pins & BSP_GPIOE_LED2) == 0) {
                 GPIO_SetBits(  GPIOE, BSP_GPIOE_LED2);
             } else {
                 GPIO_ResetBits(GPIOE, BSP_GPIOE_LED2);
             }
            break;

        case 3:
             if ((pins & BSP_GPIOE_LED3) == 0) {
                 GPIO_SetBits(  GPIOE, BSP_GPIOE_LED3);
             } else {
                 GPIO_ResetBits(GPIOE, BSP_GPIOE_LED3);
             }
            break;

        case 4:
             if ((pins & BSP_GPIOE_LED4) == 0) {
                 GPIO_SetBits(  GPIOE, BSP_GPIOE_LED4);
             } else {
                 GPIO_ResetBits(GPIOE, BSP_GPIOE_LED4);
             }
            break;

        default:
             break;
    }
}

}


                文件结构


高工
2012-06-06 12:28:20     打赏
92楼
这个帖子的含金量相当的高啊

高工
2012-06-07 20:44:57     打赏
93楼

真不简单啊


工程师
2012-06-07 21:24:55     打赏
94楼
2位楼上过奖了,真的只是“COPY”大王也,见笑见笑!!

高工
2012-06-07 21:33:36     打赏
95楼
一看就知道是做过工程的人。。。
比我的强多了。俺只是个初学者,代码有很多地方要改进的

工程师
2012-06-08 16:03:59     打赏
96楼


ARM DIY进程16: 以太网

     在淘宝网上淘到1片ENC28J60模块19.8元,包括运费不到32元(图1),做工确实还不错,还赠送调试软件和资料,挺实惠的。终于可以玩玩STM32以太网了。查阅开发板上以太网模块接口竟然与淘到的ENC28J60模块接口完全一致(图2)。用1条10芯电缆线两头一插就OK了。
    用1条RJ45网线连接ENC28J60模块到路由器上,注意这是要用直连方式,如果是直接连到PC机网卡上,就要用交叉线了。PC机上IP地址我设在192.168.1.200,ENC28J60模块设在192.168.1.45,IP地址前面3组要相同,最后的一组要错开。



                                                            图1




                                                          图2

        程序运行后,在PC机上先执行“开始-运行-CMD",输入PING 192.168.1.45,出现图3画面,可以知道开发板已经和以太网已经连接上了。接着在PC机的浏览窗口输入"HTTP://192.168.1.45/888/"(888是我在程序中设定登录密码),远程登录成功后,出现图4画面,这时,用鼠标点击屏幕中间的“开启LED”,即可点亮开发板上的4只LED,随后点击“关闭LED”图5,可关闭开发板上的4只LED。这次总算亲自体验一下STM32以太网远程控制的过程了。
  

                                 图3






                                                         图4





                                                       图5


工程师
2012-06-08 16:36:43     打赏
97楼

大部分代码都是别人写好的。驱动ENC28J60要用到SPI功能,开发板上硬件连接是用到SPI2,要修改的主要有几处:
//SPI.C
void SPI2_Init(void)
{
   SPI_InitTypeDef SPI_InitStructure;
   GPIO_InitTypeDef GPIO_InitStructure;

   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOG|RCC_APB2Periph_GPIOE, ENABLE);
   /* SPI2 Periph clock enable */
   RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);

   GPIO_SetBits(GPIOB, GPIO_Pin_12);                                            //PB12   CS
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
   GPIO_Init(GPIOB, &GPIO_InitStructure);

   GPIO_SetBits(GPIOB, GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5);
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5; //LED
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
   GPIO_Init(GPIOE, &GPIO_InitStructure);


   GPIO_SetBits(GPIOG, GPIO_Pin_7) ;                                        //PG7 RST
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
   GPIO_Init(GPIOG, &GPIO_InitStructure);

   /* Configure SPI2 pins: NSS, SCK, MISO and MOSI */                    //SPI2
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
   GPIO_Init(GPIOB, &GPIO_InitStructure);

   /* SPI2 configuration */
   SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
   SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
   SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
   SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
   SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
   SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
   SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
   SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
   SPI_InitStructure.SPI_CRCPolynomial = 7;

   SPI_Init(SPI2, &SPI_InitStructure);
   /* Enable SPI2  */
   SPI_Cmd(SPI2, ENABLE);
}

//SPI2读写一字节数据
unsigned char SPI2_ReadWrite(unsigned char writedat)
{
   /* Loop while DR register in not emplty */
   while (SPI_GetFlagStatus(SPI2, SPI_FLAG_TXE) == RESET);

   /* Send byte through the SPI1 peripheral */
   SPI_SendData(SPI2, writedat);

   /* Wait to receive a byte */
   while (SPI_GetFlagStatus(SPI2, SPI_FLAG_RXNE) == RESET);

   /* Return the byte read from the SPI bus */
   return SPI_ReceiveData(SPI2);
}

//simple_server.c
#define PSTR(s) s
static u8 mymac[6] =
{
   0x54, 0x55, 0x58, 0x10, 0x00, 0x24
};
static u8 myip[4] ={   192, 168, 1, 45};
static char baseurl[] = "http://192.168.1.45/";               //IP地址在这里修改
static u16 mywwwport = 80; 
static u16 myudpport = 1200; 
#define BUFFER_SIZE 1500
static u8 buf[BUFFER_SIZE + 1];
static char password[] = "888";                                      //密码在这里修改
u8 verify_password(char* str)
{
   if (strncmp(password, str, sizeof(password)-1) == 0)
   {
      return(1);
   }
   return(0);
}
u8 analyse_get_url(char* str)
{
   u8 i = 0;
   if (verify_password(str) == 0)
   {
      return((u8)-1);
   }
   while (*str && i<10 && *str>',' && *str < '{')
   {
      if (*str == '/')
      {
         str++;
         break;
      }
      i++;
      str++;
   }
   if (*str <0x3a && *str> 0x2f)
   {
      return(*str - 0x30);
   }
   return((u8)-2);
}
u16 print_webpage(u8* buf, u8 on_off)
{
   u16 plen;                                                                           //网页内容在这里修改
   plen = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
   plen = fill_tcp_data_p(buf, plen, PSTR(" <center><p>欢迎来到EEPW电子产品世界以太网远程控制中心</a><p>"));
   plen = fill_tcp_data_p(buf, plen, PSTR("<center><p>开发板上LED1-LED4 当前状态: "));
   if (on_off)
   {
      plen = fill_tcp_data_p(buf, plen, PSTR("<font color=\"#FF0000\"> 亮</font>"));
   }
   else
   {
      plen = fill_tcp_data_p(buf, plen, PSTR("灭"));
   }
   plen = fill_tcp_data_p(buf, plen, PSTR(" <small><a href=\""));
   plen = fill_tcp_data(buf, plen, baseurl);
   plen = fill_tcp_data(buf, plen, password);
   plen = fill_tcp_data_p(buf, plen, PSTR("\">[刷新]</a></small></p>\n<p><a href=\""));
   // the url looks like this
http://baseurl/password/command
   plen = fill_tcp_data(buf, plen, baseurl);
   plen = fill_tcp_data(buf, plen, password);
   if (on_off)
   {
      plen = fill_tcp_data_p(buf, plen, PSTR("/0\">关闭LED</a><p>"));
   }
   else
   {
      plen = fill_tcp_data_p(buf, plen, PSTR("/1\">开启LED</a><p>"));
   }
   plen = fill_tcp_data_p(buf, plen, PSTR("STM32 ARM DIY 开发板 LED 远程控制试验</a><p>"));
   plen = fill_tcp_data_p(buf, plen, PSTR("</a><p>"));
   plen = fill_tcp_data_p(buf, plen, PSTR("--Wenyangzeng DIY 进程 16--</a><p>"));

   return(plen);
}

int simple_server(void)
{
   u16 plen;
   u16 dat_p;
   u8 i = 0;
   u8 cmd_pos = 0;
   u8 cmd;
   u8 payloadlen = 0;
   char str[30];
   char cmdval;
   enc28j60Init(mymac);
   str[0]=(char)enc28j60getrev();
  
   init_ip_arp_udp_tcp(mymac, myip, mywwwport);
   enc28j60PhyWrite(PHLCON, 0x476);
   enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
   while (1)
   {
      plen = enc28j60PacketReceive(BUFFER_SIZE, buf);
      if (plen == 0)
      {
         continue;
      }
      if (eth_type_is_arp_and_my_ip(buf, plen))
      {
         make_arp_answer_from_request(buf);
         continue;
      }
      if (eth_type_is_ip_and_my_ip(buf, plen) == 0)
      {
         continue;
      }


      if (buf[IP_PROTO_P] == IP_PROTO_ICMP_V &&
         buf[ICMP_TYPE_P] == ICMP_TYPE_ECHOREQUEST_V)
      {
          make_echo_reply_from_request(buf, plen);
         continue;
      }
      if (buf[IP_PROTO_P] == IP_PROTO_TCP_V &&
         buf[TCP_DST_PORT_H_P] == 0 &&
         buf[TCP_DST_PORT_L_P] == mywwwport)
      {
         if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V)
         {
            make_tcp_synack_from_syn(buf);
             continue;
         }
         if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V)
         {
            init_len_info(buf); // init some data structures
            dat_p = get_tcp_data_pointer();
            if (dat_p == 0)
            {
               if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V)
               {
                  make_tcp_ack_from_any(buf);
               }
               continue;
            }
            if (strncmp("GET ", (char *) &(buf[dat_p]), 4) != 0)
            {
               plen = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>200 OK</h1>"));
               goto SENDTCP;
            }
            if (strncmp("/ ", (char *) &(buf[dat_p + 4]), 2) == 0)
            {
               plen = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));
               plen = fill_tcp_data_p(buf, plen, PSTR("<p>Usage: "));
               plen = fill_tcp_data(buf, plen, baseurl);
               plen = fill_tcp_data_p(buf, plen, PSTR("password</p>"));
               goto SENDTCP;
            }
            cmd = analyse_get_url((char *) &(buf[dat_p + 5]));
            if (cmd ==(u8)-1)
            {
               plen = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n<h1>401 Unauthorized</h1>"));
               goto SENDTCP;
            }
             if (cmd == 1)
            {                                                          / /LED控制在这里修改
  GPIO_ResetBits(GPIOE,GPIO_Pin_5);
    GPIO_ResetBits(GPIOE,GPIO_Pin_4);
  GPIO_ResetBits(GPIOE,GPIO_Pin_3);
  GPIO_ResetBits(GPIOE,GPIO_Pin_2);
               i = 1;
            } else
            if (cmd == 0)
            {
     GPIO_SetBits(GPIOE,GPIO_Pin_5);
   GPIO_SetBits(GPIOE,GPIO_Pin_4);
    GPIO_SetBits(GPIOE,GPIO_Pin_3);
      GPIO_SetBits(GPIOE,GPIO_Pin_2);
               i = 0;
            }
            plen = print_webpage(buf, (i));

   SENDTCP :
            make_tcp_ack_from_any(buf);
            make_tcp_ack_with_data(buf, plen);
            continue;
         }
      }

      if (buf[IP_PROTO_P] == IP_PROTO_UDP_V &&
         buf[UDP_DST_PORT_H_P] == 4 &&
         buf[UDP_DST_PORT_L_P] == 0xb0)
      {
         payloadlen = buf[UDP_LEN_L_P] - UDP_HEADER_LEN;
         if (verify_password((char *) &(buf[UDP_DATA_P])))
         {
            cmd_pos = 0;
            while (cmd_pos < payloadlen)
            {
               cmd_pos++;
               if (buf[UDP_DATA_P + cmd_pos] == ',')
               {
                  cmd_pos++;
                  break;
               }
            }
            if (cmd_pos<2 ||
               cmd_pos>payloadlen - 3 ||
               buf[UDP_DATA_P + cmd_pos + 1] != '=')
            {
               strcpy(str, "e=no_cmd");
               goto ANSWER;
            }
            if (buf[UDP_DATA_P + cmd_pos] == 't')
            {
               cmdval = buf[UDP_DATA_P + cmd_pos + 2];
               if (cmdval == '1')
               {
                  strcpy(str, "t=1");
                  goto ANSWER;
               }
               else if (cmdval == '0')
               {
                  strcpy(str, "t=0");
                  goto ANSWER;
               }
               else if (cmdval == '?')
               {
                  strcpy(str, "t=0");
                  goto ANSWER;
               }
            }
            strcpy(str, "e=no_such_cmd");
            goto ANSWER;
         }
         strcpy(str, "e=invalid_pw");
         ANSWER : make_udp_reply_from_request(buf, str, strlen(str), myudpport);
      }
   }
}


工程师
2012-06-08 20:05:07     打赏
98楼

 ARM DIY进程17 DAC 

      采用DAC方式从PA4,PA5输出2路正弦波,DAC由定时器2触发,32个16位正弦波数据以DMA方式传输给DAC。整个过程很简单,采用DAC方式转换速度很快,从运行结果(图1)可以看到:虽然正弦波的频率达到28.8KHZ,但是波形却非常光滑。



                                           图1
代码很简单:
#include "stm32f10x.h"

#define DAC_DHR12RD_Address      0x40007420

DAC_InitTypeDef            DAC_InitStructure;
DMA_InitTypeDef            DMA_InitStructure;
TIM_TimeBaseInitTypeDef    TIM_TimeBaseStructure;
uint32_t Idx = 0;  
const uint16_t Sine12bit[32] = {
                      2047, 2447, 2831, 3185, 3498, 3750, 3939, 4056, 4095, 4056,
                      3939, 3750, 3495, 3185, 2831, 2447, 2047, 1647, 1263, 909,
                      599, 344, 155, 38, 0, 38, 155, 344, 599, 909, 1263, 1647};

uint32_t DualSine12bit[32];

void RCC_Configuration(void);
void GPIO_Configuration(void);
void Delay(__IO uint32_t nCount);

int main(void)
{
  RCC_Configuration();  

  GPIO_Configuration();

  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
  TIM_TimeBaseStructure.TIM_Period = 0x19;         
  TIM_TimeBaseStructure.TIM_Prescaler = 0x0;      
  TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;   
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

  TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);

  DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;
  DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
  DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
  DAC_Init(DAC_Channel_1, &DAC_InitStructure);

  DAC_Init(DAC_Channel_2, &DAC_InitStructure);

  for (Idx = 0; Idx < 32; Idx++)
  {
    DualSine12bit[Idx] = (Sine12bit[Idx] << 16) + (Sine12bit[Idx]);
  }

  DMA_DeInit(DMA2_Channel4);
  DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_Address;
  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&DualSine12bit;
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
  DMA_InitStructure.DMA_BufferSize = 32;
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

  DMA_Init(DMA2_Channel4, &DMA_InitStructure);
  DMA_Init(DMA1_Channel4, &DMA_InitStructure);
  DMA_Cmd(DMA1_Channel4, ENABLE);
  DAC_Cmd(DAC_Channel_1, ENABLE);
  DAC_Cmd(DAC_Channel_2, ENABLE);

  DAC_DMACmd(DAC_Channel_2, ENABLE);

  TIM_Cmd(TIM2, ENABLE);

  while (1)
  {
  }
}

void RCC_Configuration(void)
{   
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
}

void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4 | GPIO_Pin_5;//DAC输出
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
}

void Delay(__IO uint32_t nCount)
{
  for(; nCount != 0; nCount--);
}


高工
2012-06-08 20:14:10     打赏
99楼
我的帖子里边给出了四线sd卡驱动,你看看吧。

工程师
2012-06-08 20:15:56     打赏
100楼
谢谢楼上!

共107条 10/11 |‹ 6 7 8 9 10 11 跳转至

回复

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