Hiện tại em đang làm đề tài sử dụng con MT8888 để phát tone, mình viết chương trình không rõ sai chỗ nào mà không thấy chạy, trên diễn đàn có ai làm rồi chỉ cho em với
em có viết thử chương trình để xem MT8888 có hoạt động không, khi nhấn nút thì nó sẽ truyền đi 1 số, có ngắt xảy ra sẽ báo lên lcd mà trả thấy ngắt hoạt động, lấy tín hiệu từ đầu ra tone cho vào 1 mạch thu DTMF dùng MT8870 (đã test với tone điện thoại chạy) mà cũng không có hiện tượng gì xảy ra,
Mọi người cho em xin ý kiến với ạ
em có thử đo các đầu ra D0-D3 thì giống như số cần phát đi,
#include <mega8.h>
#include <alcd.h>
#include <delay.h>
#include <stdio.h>
#define CS PORTB.7
#define RS0 PORTB.6
#define WR PORTB.5
#define RD PORTD.4
#define PORT_DTMF PORTB // D3,D2,D1,D0 -- B3,B2,B1,B0
#define DDR_DTMF DDRB
#define IRQ PORTD.3 // chan ngat ngoai
#define Set PINC.0
#define Up PINC.1
#define Dw PINC.2
unsigned char data,number;
char lcd_dis[15];
void MT8888_int()
{
//1.Read Status Register
DDR_DTMF = 0xF0;
delay_us(2);
PORT_DTMF = 0xFF;
delay_us(2);
CS = 0;
RD = 0;
delay_us(2);
RD = 1;
delay_us(10);
//2.Write to Control Register
DDR_DTMF = 0xFF;
delay_us(2);
PORT_DTMF = 0xF0;
delay_us(2);
CS = 0;
WR = 0;
delay_us(2);
WR = 1;
delay_us(10);
//3.Write to Control Register
DDR_DTMF = 0xFF;
delay_us(2);
PORT_DTMF = 0xF0;
delay_us(2);
CS = 0;
WR = 0;
delay_us(2);
WR = 1;
delay_us(10);
//4.Write to Control Register
DDR_DTMF = 0xFF;
delay_us(2);
PORT_DTMF = 0xF8;
delay_us(2);
CS = 0;
WR = 0;
delay_us(2);
WR = 1;
delay_us(10);
//5.Write to Control Register
DDR_DTMF = 0xFF;
delay_us(2);
PORT_DTMF = 0xF0;
delay_us(2);
CS = 0;
WR = 0;
delay_us(2);
WR = 1;
delay_us(10);
//6.Read Status Register
DDR_DTMF = 0xF0;
delay_us(2);
PORT_DTMF = 0xFF;
delay_us(2);
CS = 0;
RD = 0;
delay_us(2);
RD = 1;
delay_ms(1000);
}
void MT8888_setup()
{
//1.Write to Control Register A (tone out, DTMF, IRQ, Select Control Register B)
DDR_DTMF = 0xFF;
delay_us(2);
PORT_DTMF = 0xFD;
delay_us(2);
CS = 0;
WR = 0;
delay_us(2);
WR = 1;
delay_us(10);
//2.Write to Control Register B (burst mode)
DDR_DTMF = 0xFF;
delay_us(2);
PORT_DTMF = 0xF0;
delay_us(2);
CS = 0;
WR = 0 ;
delay_us(2);
WR = 1;
delay_us(10);
}
void MT8888_transmit(unsigned char num)
{
unsigned char DTMF[16]={0xFA,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF 9,0xFB,0xFC,0xFD,0xFE,0xFF,0x00};
char result;
//1.Write to Transmit Data Register
DDR_DTMF = 0xFF;
delay_us(2);
PORT_DTMF = DTMF[num];
delay_us(2);
CS = 0;
RS0 = 0;
WR = 0;
delay_us(2);
WR = 1;
//2.Wait for an interrupt or poll Status Register
delay_ms(100);
//3.Read the Status Register
result = 0;
DDR_DTMF = 0xF0;
while(result!=2)
{
CS = 0;
RS0 = 1;
WR = 1;
RD = 1;
result = (PINB & 0x02);
delay_us(10);
RD = 0;
delay_us(2);
RD = 1;
CS = 1;
};
// delay_ms(200);
}
interrupt [EXT_INT1] void ext_int1_isr(void)
{
delay_ms(100);
data++;
}
// Declare your global variables here
void main(void)
{
PORTB=0xFF;
DDRB=0xFF;
PORTC=0x07;
DDRC=0x00;
PORTD=0xFF;
DDRD=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: On
// INT1 Mode: Rising Edge
GICR|=0x80;
MCUCR=0x0C;
GIFR=0x80;
// RS - PORTD Bit 0
// RD - PORTD Bit 1
// EN - PORTD Bit 2
// D4 - PORTD Bit 4
// D5 - PORTD Bit 5
// D6 - PORTD Bit 6
// D7 - PORTD Bit 7
// Characters/line: 16
lcd_init(16);
delay_ms(200);
MT8888_int();
delay_ms(100);
MT8888_setup();
MT8888_transmit(2);
lcd_clear();
#asm("sei")
//number = 0;
while (1)
{
if(!Up)
{
number++;
MT8888_setup();
MT8888_transmit(number);
if(number==16) number = 0;
delay_ms(200);
}
if(!Dw)
{
number--;
MT8888_setup();
MT8888_transmit(number);
if(number==255) number = 15;
delay_ms(200);
}
sprintf(lcd_dis,"Num0: %3d ",data); // xem ngat co hoat dong khong
lcd_gotoxy(0,0);
lcd_puts(lcd_dis);
sprintf(lcd_dis,"Num1: %3d ",number); // bao so duoc truyen di
lcd_gotoxy(0,1);
lcd_puts(lcd_dis);
}
}
#include <alcd.h>
#include <delay.h>
#include <stdio.h>
#define CS PORTB.7
#define RS0 PORTB.6
#define WR PORTB.5
#define RD PORTD.4
#define PORT_DTMF PORTB // D3,D2,D1,D0 -- B3,B2,B1,B0
#define DDR_DTMF DDRB
#define IRQ PORTD.3 // chan ngat ngoai
#define Set PINC.0
#define Up PINC.1
#define Dw PINC.2
unsigned char data,number;
char lcd_dis[15];
void MT8888_int()
{
//1.Read Status Register
DDR_DTMF = 0xF0;
delay_us(2);
PORT_DTMF = 0xFF;
delay_us(2);
CS = 0;
RD = 0;
delay_us(2);
RD = 1;
delay_us(10);
//2.Write to Control Register
DDR_DTMF = 0xFF;
delay_us(2);
PORT_DTMF = 0xF0;
delay_us(2);
CS = 0;
WR = 0;
delay_us(2);
WR = 1;
delay_us(10);
//3.Write to Control Register
DDR_DTMF = 0xFF;
delay_us(2);
PORT_DTMF = 0xF0;
delay_us(2);
CS = 0;
WR = 0;
delay_us(2);
WR = 1;
delay_us(10);
//4.Write to Control Register
DDR_DTMF = 0xFF;
delay_us(2);
PORT_DTMF = 0xF8;
delay_us(2);
CS = 0;
WR = 0;
delay_us(2);
WR = 1;
delay_us(10);
//5.Write to Control Register
DDR_DTMF = 0xFF;
delay_us(2);
PORT_DTMF = 0xF0;
delay_us(2);
CS = 0;
WR = 0;
delay_us(2);
WR = 1;
delay_us(10);
//6.Read Status Register
DDR_DTMF = 0xF0;
delay_us(2);
PORT_DTMF = 0xFF;
delay_us(2);
CS = 0;
RD = 0;
delay_us(2);
RD = 1;
delay_ms(1000);
}
void MT8888_setup()
{
//1.Write to Control Register A (tone out, DTMF, IRQ, Select Control Register B)
DDR_DTMF = 0xFF;
delay_us(2);
PORT_DTMF = 0xFD;
delay_us(2);
CS = 0;
WR = 0;
delay_us(2);
WR = 1;
delay_us(10);
//2.Write to Control Register B (burst mode)
DDR_DTMF = 0xFF;
delay_us(2);
PORT_DTMF = 0xF0;
delay_us(2);
CS = 0;
WR = 0 ;
delay_us(2);
WR = 1;
delay_us(10);
}
void MT8888_transmit(unsigned char num)
{
unsigned char DTMF[16]={0xFA,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF 9,0xFB,0xFC,0xFD,0xFE,0xFF,0x00};
char result;
//1.Write to Transmit Data Register
DDR_DTMF = 0xFF;
delay_us(2);
PORT_DTMF = DTMF[num];
delay_us(2);
CS = 0;
RS0 = 0;
WR = 0;
delay_us(2);
WR = 1;
//2.Wait for an interrupt or poll Status Register
delay_ms(100);
//3.Read the Status Register
result = 0;
DDR_DTMF = 0xF0;
while(result!=2)
{
CS = 0;
RS0 = 1;
WR = 1;
RD = 1;
result = (PINB & 0x02);
delay_us(10);
RD = 0;
delay_us(2);
RD = 1;
CS = 1;
};
// delay_ms(200);
}
interrupt [EXT_INT1] void ext_int1_isr(void)
{
delay_ms(100);
data++;
}
// Declare your global variables here
void main(void)
{
PORTB=0xFF;
DDRB=0xFF;
PORTC=0x07;
DDRC=0x00;
PORTD=0xFF;
DDRD=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: On
// INT1 Mode: Rising Edge
GICR|=0x80;
MCUCR=0x0C;
GIFR=0x80;
// RS - PORTD Bit 0
// RD - PORTD Bit 1
// EN - PORTD Bit 2
// D4 - PORTD Bit 4
// D5 - PORTD Bit 5
// D6 - PORTD Bit 6
// D7 - PORTD Bit 7
// Characters/line: 16
lcd_init(16);
delay_ms(200);
MT8888_int();
delay_ms(100);
MT8888_setup();
MT8888_transmit(2);
lcd_clear();
#asm("sei")
//number = 0;
while (1)
{
if(!Up)
{
number++;
MT8888_setup();
MT8888_transmit(number);
if(number==16) number = 0;
delay_ms(200);
}
if(!Dw)
{
number--;
MT8888_setup();
MT8888_transmit(number);
if(number==255) number = 15;
delay_ms(200);
}
sprintf(lcd_dis,"Num0: %3d ",data); // xem ngat co hoat dong khong
lcd_gotoxy(0,0);
lcd_puts(lcd_dis);
sprintf(lcd_dis,"Num1: %3d ",number); // bao so duoc truyen di
lcd_gotoxy(0,1);
lcd_puts(lcd_dis);
}
}
Mọi người cho em xin ý kiến với ạ
em có thử đo các đầu ra D0-D3 thì giống như số cần phát đi,