|
楼主 |
发表于 2004-11-16 17:33:08
|
显示全部楼层
我自己写了一个通讯的接收模块,保证通过(使用网卡转串口的模块测试的)
#include <iom8v.h>
#include <macros.h>
#include <eeprom.h>
char data=0;
void uart0_init(void);
void usart_rcx(void);
#pragma interrupt_handler usart_rcx:12 //USART接受中断
const char dispCode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0x40,0x63};
const char dispBit[] = {0b0000001,0b0000010,0b00000100,0b00001000,0b00010000,0b00100000,0b01000000,0b10000000};
int time_cont =0;
#pragma interrupt_handler timer1_ovf:9
//***************************************
void send_data(char disp_data);
void int_dvice(void);
void int_port(void);
void int_timer(void);
void display(unsigned char bitselect ,unsigned char numbers);
void timer1_ovf(void);
//***************************************
void int_dvice(void)
{
CLI();
int_port();
int_timer();
SEI(); //re-enable interrupts
TIMSK|=0B00000101;
GICR=0x40;
}
void int_port(void)
{
DDRC =0XFF;
PORTC =0;
}
void int_timer(void)
{
//定时器1部分
TCNT1H = 0xE0;
TCNT1L = 0xC0;
TCCR1B = 0x01; //1分频,定时1ms
}
//
void display(unsigned char bitselect ,unsigned char numbers)
{
PORTC &=0B11111101;
//send_data(0b00000001);
send_data(dispBit[bitselect]);
send_data(dispCode[numbers]);//
//disp_buff[bit_select];
PORTC |=0B00000010; //
//bit_select++;
//if(bit_select ==7)
// bit_select =0;
}
void send_data(char disp_data)
{
char i;
for(i =0;i<8;i++)
{
if(((disp_data <<i)& 0x80) ==0)
{
PORTC &=0B11110111;
}
else
{
PORTC |=0B00001000;
}
PORTC |=0B00000100;
PORTC &=0B11111011;
}
}
void timer1_ovf(void) //1ms中断程序,检测主程序标志
{
char a=0;
TCNT1H = 0xF8;
TCNT1L = 0xC0;
time_cont++;
if(time_cont >1000)
{
time_cont =0;
}
display(1,data-(data/10)*10);
a=data/10;
display(2,a-(a/10)*10);
a=data/100;
display(3,a-(a/10)*10);
//显示数据
}
void uart0_init(void) //接收初始化
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = 0x00;
UBRR = 12; //set baud rate
UCSRB = 0x90; //开启接收中断
UCSRC = 0xA6; //开启USART系统
}
void main(void)
{
DDRD=0x00;
PORTD=0x00;
DDRB=0xff;
PORTB=0xff;
uart0_init();
int_dvice();
SEI();
while(1)
{ }
}
void usart_rcx(void)
{
data =UDR;
PORTB=data;
} |
|