⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 非常全的nrf2401设计资料
💻 C
字号:
/* Copyright (c) 2008 Nordic Semiconductor. All Rights Reserved.
 *
 * The information contained herein is confidential property of Nordic 
 * Semiconductor. The use, copying, transfer or disclosure of such information 
 * is prohibited except by express written agreement with Nordic Semiconductor.
 *
 * $LastChangedRevision$
 */

/** @file
 * nRF24LE1 and nRF6350 example application main file
 *
 * @author Rune Brandsegg
 */

#include <Nordic\reg24le1.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "nordic_common.h"
#include "lib_nrf6350.h"

#define CNT_INIT 0x06FF

void use_joystick(void);
void left(void);
void right(void);
void up(void);
void down(void);
void pushed(void);

static char string[] = " "; 
static uint8_t line = 0, col = 0, caps = 0x40, max = 0x1A;


void main(void)
{
  char text1u[] = "Use joystick to";
  char text1l[] = "write on display";
  char text2u[] = "Push joystick";
  char text2l[] = "to start";
 
  uint16_t i,j;  

  lcd_init();
  js_button_pushed();                   // Dummy read to ensure initialization
   
  while(!js_button_pushed())
  {  
    lcd_clear(); 
    lcd_write_string(text1u, 0, 0); 
    lcd_write_string(text1l, 1, 0);      
  
    for(i = 0; i < 30000; i++)
    {
      for(j = 0; j < 10; j++)
        ;
      if(js_button_pushed())
      {
        break;                          // End loop if joystick is pressed
      }  
    }
    lcd_clear();
    lcd_write_string(text2u, 0, 0); 
    lcd_write_string(text2l, 1, 0);  
  
    for(i = 0; i < 30000; i++)
    {
      for(j = 0; j < 10; j++)
        ;
      if(js_button_pushed())
      {
        break;                          // End loop if joystick is pressed
      }    
    }
  }
  while(js_button_pushed())             // Hold until joystick is released
    ;
  use_joystick();                       // Go to the actual application
}

void use_joystick(void)
{
  int8_t from_js[2];
  uint8_t position = 0x00;
  uint16_t cnt = CNT_INIT; 

  lcd_clear();                                

  while(1)
  {
    js_get_value(from_js);              // Retrieve joystick position

/* Control of the automatic lineshift */
    if(line == 0 && col == 0xFF)         
    {                                   // If line 0 is cleared and col counter 
      col = 0;                          // wraps, reset the col counter.
    }
    if(line == 1 && col == 16)          
    {                                   // If line 1 is full, stay in the last
      col = 15;                         // position.
    }
    if(line == 0 && col == 16)          
    {                                   // If line 0 is full, change to line 1
      col = 0;                          // and reset the col counter.
      line = 1;
    }
    if(line == 1 && col == 0xFF)         
    {                                   // If line 1 is cleared and col counter
      col = 15;                         // wraps, change to line 0 and set col 
      line = 0;                         // counter to last position.
    }   

/* Detection of joystick position */
    if(from_js[0] != 0 && from_js[1] != 0)
      ;
    else if(from_js[0] > 0)
    {
      if(position != 1)
      {
        right();      
        position = 1;
      }
    }
    else if(from_js[0] < 0)
    {
      if(position != 2)
      {
        left(); 
        position = 2;
      }
    }
    else if(from_js[1] > 0)
    {
      if(position != 3)
      {
        down(); 
        position = 3;
        cnt = CNT_INIT;
      }
      cnt--;
    }
    else if(from_js[1] < 0)
    {
      if(position != 4)
      {
        up();
        position = 4;
        cnt = CNT_INIT;
      }
      cnt--;
    }
    else if(js_button_pushed())
    {
      if(position != 5)
      {
        pushed();
        position = 5;
      }
    }
    else if(from_js[0] == 0 && from_js[1] == 0)
    {
      position = 0x00;
    }
    if(cnt == 0)
    {
      position = 0x00;
    }
  }
}

void left(void)
{
  string[0] = 0x20; 
  lcd_write_string(string, line, col);  
  col--;  
}

void right(void)
{
  string[0] = 0x20;
  col++;
}
void up(void)
{
  if(string[0] == 0x20)
  {
    string[0] = caps;
  }
  if(string[0] == (caps + max - 1))
  {
    string[0] = caps;
  }
  string[0] = string[0] + 1; 
  lcd_write_string(string, line, col);
  
}
void down(void)
{
  if(string[0] == 0x20)
  {
    string[0] = caps + max;
  } 
  if(string[0] == caps + 1)
  {
    string[0] = caps + max;
  }
  string[0] = string[0] - 1; 
  lcd_write_string(string, line, col);  
}
void pushed(void)
{
  switch(caps)
  {
    case 0x40:
      caps = 0x60;
      max = 0x1B;
      break;
    case 0x60:
      caps = 0x2F;
      max = 0x0B;
      break;
    case 0x2F:
      caps = 0x40;
      max = 0x1B;
      break;
    default:
      break;
  }
  string[0] = 0x20;
}                           

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -