iar10-2.c

来自「手把手教你学AVR单片机C程序设计实验程序」· C语言 代码 · 共 97 行

C
97
字号
#include <iom16.h>
#include<intrinsics.h>
#include "lcd1602_8bit.c"
#define uchar unsigned char
#define uint unsigned int
#define UDRE 5
#define RXC 7
#define xtal 8
uchar __flash str1[]="ATmega16 LCD DIS";
uchar dat[7];
/*************************************************/
void port_init(void) 
{
 PORTA = 0xFF; 
 DDRA  = 0x00; 
 PORTB = 0xFF; 
 DDRB  = 0xFF; 
 PORTC = 0xFF; 
 DDRC  = 0x00; 
 PORTD = 0xFF;
 DDRD  = 0x02; 
}
/**************************************************/
void uart0_init(void) 
{
 UCSRB = 0x00; 
 UCSRA = 0x02;
 UCSRC = 0x06;
 UBRRL = 0x67; 
 UBRRH = 0x00; 
 UCSRB = 0x18;
}
/********************************************************/
void init_devices(void) 
{
 port_init();
 uart0_init();
 }
//**********************************************
void uart0_send(unsigned char i)
{
while(!(UCSRA&(1<<UDRE)));
UDR=i;
}
/*******************************************/
void str_send(char *s) 
{
 while(*s)
 {
 uart0_send(*s); 
 s++;
 }
}
/*********************************************/
unsigned char uart0_receive(void) 
{
while(!(UCSRA&(1<<RXC)));
return UDR;
}
/********************************************/
void main(void) 
{
uchar temp,s=0; 
init_devices();
Delay_nms(400);
InitLcd();
ePutstr(0,0,str1);
 while(1) 
 { 
   while(s<7)
   {  
   temp=uart0_receive();
   dat[s]=temp;
   s++;
   }
   s=0;
   str_send("当前的数据是:");
   while(s<7)
   {
    uart0_send(dat[s]); 
    s++;
   }
   s=0;
  uart0_send(0x0D);
  uart0_send(0x0A);  
   DisplayOneChar(0,1,'D');
   DisplayOneChar(1,1,':'); 
   DisplayOneChar(2,1,dat[0]); 
   DisplayOneChar(4,1,dat[1]); 
   DisplayOneChar(6,1,dat[2]); 
   DisplayOneChar(8,1,dat[3]); 
   DisplayOneChar(10,1,dat[4]); 
   DisplayOneChar(12,1,dat[5]); 
   DisplayOneChar(14,1,dat[6]); 
 }	
}

⌨️ 快捷键说明

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