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

📄 remote.c

📁 用ATmega128做的mp3播放器
💻 C
字号:
#include <iom128v.h>
#include "remote.h"
#include "vs1001.h"
#include "fat.h"
#include "generic.h"
#include <string.h>
#include <stdio.h>
#include <macros.h>

//******************************************************************
//*	Global Variable
//******************************************************************
extern unsigned char Key;
extern unsigned char RemoteTextLine[5][40];

//******************************************************************
//*	INITIALIZE HARDWARE FOR SERIAL INTERFACE 
//*   
//*   
//******************************************************************
void InitRemote(void)
{
UCSR1B = 0x00; //disable while setting baud rate
UCSR1A = 0x00; 
UCSR1C = 0x8e; // Asyn,NoParity,2StopBit,8Bit,
UBRR1H = 0x01; // set baud rate hi
UBRR1L = 0xa0; // set baud rate low for 2400 at 16Mhz
UCSR1B = 0x98; // Rx enable Tx Enable
}

//******************************************************************
//*	void RemoteSendLine(unsigned char LinePtr)
//*   
//* 
//******************************************************************
void RemoteSendLine(unsigned char LinePtr)
{
char text[255];

sprintf(&text[0],"%c%s\0",0x81+LinePtr,&RemoteTextLine[LinePtr][0]);
SendRemote(&text[0]);

sprintf(&text[0],"%c\0",0xa1+LinePtr);
SendRemote(&text[0]);
}

//******************************************************************
//*	void RemoteSendScreen(unsigned char Header,unsigned char LinePtr)
//*   
//* 
//******************************************************************
void RemoteSendScreen(unsigned char Header,unsigned char LinePtr)
{
char text[255];
				
sprintf(&text[0],"%c\0",0x80);  // Clear Screen
SendRemote(&text[0]);

if (Header == DIR) sprintf(&text[0],"%c\0",0x91); 
if (Header == FILE) sprintf(&text[0],"%c\0",0x90);  
if (Header == PLAY) sprintf(&text[0],"%c\0",0x92);   
SendRemote(&text[0]);
				
sprintf(&text[0],"%c%s\0",0x81,&RemoteTextLine[0][0]);
if (LinePtr != 0) text[14] = 0x00;
SendRemote(&text[0]);
				
sprintf(&text[0],"%c%s\0",0x82,&RemoteTextLine[1][0]);
if (LinePtr != 1) text[14] = 0x00;
SendRemote(&text[0]);

sprintf(&text[0],"%c%s\0",0x83,&RemoteTextLine[2][0]) ;
if (LinePtr != 2) text[14] = 0x00;
SendRemote(&text[0]);

sprintf(&text[0],"%c%s\0",0x84,&RemoteTextLine[3][0]);
if (LinePtr != 3) text[14] = 0x00;
SendRemote(&text[0]);

sprintf(&text[0],"%c%s\0",0x85,&RemoteTextLine[4][0]) ;
if (LinePtr != 4) text[14] = 0x00;
SendRemote(&text[0]);

sprintf(&text[0],"%c\0",0xa1+LinePtr);
SendRemote(&text[0]);		

sprintf(&text[0],"%c\0",0xb0);
SendRemote(&text[0]);		
}

//******************************************************************
//*	void SendRemote(char *buffer)
//*   
//* 
//******************************************************************
void SendRemote(char *buffer)
{
int i;

UCSR1B &= ~0x80; // Rx int disable
i = 0;
TxChar(0x55);
TxChar(0x55);
TxChar(0xf0);
while (buffer[i] != 0x00)
        {
        SendByte(buffer[i++]);
        }
TxChar(0x0f);

while (!(UCSR1A & 0x40)); 	  // Wait for the char to be cue off
delay_ms(50);

i = UDR1;
UCSR1A |= 0x40;  
UCSR1B |= 0x80; // Rx int enable
}

//******************************************************************
//*	void SendByte(unsigned char TxByte)
//*   
//* Manchester encode byte and send it
//******************************************************************
void SendByte(unsigned char TxByte)
{
unsigned char i,j,me;

for (i=0; i<2; i++)
    {
	WDR();
    me = 0;         // manchester encoded txbyte
    for (j=0 ; j<4; j++)
        {
        me >>=2;
        if (TxByte & 0x01)
                {
                me |= 0x80;
                }
        else
                {
                me |= 0x40;
                }
        TxByte >>=1;
        }
    TxChar(me);
    }
delay_ms(1);
}

//******************************************************************
//*	TxChar(unsigned char ch)
//*   
//* Send a byte to the remote  
//******************************************************************
void TxChar(unsigned char ch)
{
while (!(UCSR1A & 0x20)) WDR(); 
UDR1 = ch;
}

//******************************************************************
//*	void RxChar(void)
//*   
//* Send a byte to the remote  
//******************************************************************
#pragma interrupt_handler RxChar:31
void RxChar(void)
{
static unsigned char ch,TempKey;
static unsigned char Error;
static unsigned char Qte = 0;

ch = UDR1;

if ((ch == 0xf0) && (Key == 0))
   {
   Qte = 1;
   Error = FALSE;
   return;
   }

if ((ch == 0x0f) && (Error == FALSE))
   {
   Qte = 0;
   Key = TempKey;
   return;
   }

if (Qte == 1)
   {
   TempKey = ch;
   Qte++;
   return;
   }

if ((Qte == 2) && (TempKey != ~ch))
   {
   Error = TRUE;
   Qte++;
   return;
   }
}

⌨️ 快捷键说明

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