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

📄 simpleio.c

📁 CC1020的源代码,详细介绍CC1020的配置和开发,
💻 C
字号:
/****************************************************************************/
/* Application note AN015                                                   */
/* Reference design : CC1000 RF Modem                                       */
/*                                                                          */
/* File:      simpleio.c                                                    */
/*                                                                          */
/* Microcontroller:                                                         */
/*          Microchip PIC16F876                                             */
/*                                                                          */
/* Author:  Karl H. Torvmark, Field Applications Engineer, Chipcon          */
/*                                                                          */
/* Contact: Chipcon AS +47 22 95 85 44                                      */
/*          wireless@chipcon.com                                            */
/****************************************************************************/

/****************************************************************************/
/* This file contains routines for simple output of strings, integers and   */
/* hexadecimal values. Using these routines instead of printf() saves large */
/* amounts of program memory.                                               */
/****************************************************************************/

/*                                                                           *
 * Revision history:                                                         *
 *                                                                           *
 * $Log: simpleio.c,v $
 * Revision 1.2  2003/09/17 15:03:08  tos
 * Mod's:
 *   - introduced new menu option ('J'): access (w/r) CC1020 register.
 *   - update EEPROM variable+table upon register write access ('J').
 *   - introduced new configuration option ('I'): preamble length.
 *   - moved TX buffer initialisation after configuration.
 *   - corrected inconsistent number conversion funtion.
 *
 *
 *
 *                                                                           *
 ****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "simpleio.h"

/****************************************************************************/
/* This routine outputs a string                                            */
/****************************************************************************/

void writestr(const char *str)
{
  while (*str!='\0') {
    putchar(*str++);
  }
}

/****************************************************************************/
/* This routine outputs a string, and also outputs trailing new-line and    */
/* carrage return characters                                                */
/****************************************************************************/

void writeln(const char *str)
{
  while (*str!='\0') {
    putchar(*str++);
  }
  putchar('\n');
  putchar('\r');
}

/****************************************************************************/
/* This routine converts an ASCII hexadecimal digit to the corresponding    */
/* integer value                                                            */
/****************************************************************************/

char hexdigit2int(char val)
{
  if ((val>=0x30)&&(val<=0x39))
    return val-0x30;
  if ((toupper(val)>=0x41)&&(toupper(val)<=0x46))
    return val-0x41+10;
    
  return 0x00;
}

/****************************************************************************/
/* This routine outputs a long value in decimal                             */
/****************************************************************************/


void writelong(long longval)
{
  char i;
  long divider;
  
  divider=1000000000;
  
  for (i=10;i>0;i--) {
    putchar((longval/divider)+0x30);
    divider/=10;
  }
    
}

/****************************************************************************/
/* This routine outputs an int (in hexadecimal)                             */
/****************************************************************************/

void writehex(int hexval)
{
  char i;
  
  int temp;
  
  char val;
  
  putchar('0');
  putchar('x');
  
  temp=hexval;
  
  for(i=0;i<4;i++) {
    val=(temp&0xF000)>>12;
    if (val<=9) {
      putchar(val+0x30);
    } else {
      putchar(val+0x41-0xA);
    }
    temp=(temp<<4);
  }
}


/********************************************************************************/
/* This routine outputs an integer value in decimal, without preceeding zero's  */
/********************************************************************************/

void writeint(int num)
{
  char i;
  char digit_start = 0;
  int digit = 0;
  int denom = 10000;

  for(i = 5; i > 0; i--){
    digit = num/denom;
    if((digit_start == 1) || (digit != 0)){
      digit_start = 1;
      num %= denom;
      putchar(digit+'0');
    }else{
    }
    denom/=10;
  }

}


⌨️ 快捷键说明

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