本帖最后由 ad25fgh30 于 2013-1-9 11:14 编辑
帮忙啊大神们
OSCCON = 0b01110110; // Fosc=16M
OSCCON2 = 0b10000101;
OSCTUNE = 0b01000000; // 2012.2 enable PLL
// T1CON = 0B01001111;
TRISA = 0b00111111; // PORTA bits 7:4 are all outputs (0)
TRISB = 0b11110011;//0b00000011; // PORTB
TRISC = 0b00000000; // PORTC SCL/SDA 除外
这是寄存器的设置
但是这样做可以控制端口,但无法实现与1621之间的数据传输啊
void main (void)
{
OSCCON = 0b01110110; // Fosc=16M
OSCCON2 =0b01000111;
OSCTUNE = 0b01000000; // 2012.2 enable PLL
// T1CON = 0B01001111;
TRISA = 0b00111111; // PORTA bits 7:4 are all outputs (0)
TRISB = 0b11110011;//0b00000011; // PORTB
TRISC = 0b10000000; // PORTC SCL/SDA 除外
// PORTC=0b00000000;
// PORTA=0b00000000;
// RCONbits.IPEN = 1; // Enable priority levels on interrupts
// INTCONbits.GIEL = 1; // Low priority interrupts allowed
// INTCONbits.GIEH = 1; // Interrupting enabled.
key=0;
Init_1621();
HT1621_all_off();
LCDon();
/******************************* en WDT ************************************/
// WDTCONbits.SWDTEN = 1;
while(1)
{
HT1621_all_on();
PORTB=0x08;
}
}
/**-------------------------------------------------------------------------
Name: SendBit_1621(送数据程序)
---------------------------------------------------------------------------*/
void SendBit_1621(uchar sdata,uchar cnt) //data 的高cnt 位写入HT1621,高位在前
{
//uchar i_s;
for(i_s=0;i_s<cnt;i_s++)
{
PORTCbits.RC1=1;//WR0;
if(sdata&0x80)
PORTCbits.RC2=0;//DATA1;
else
PORTCbits.RC2=1;//DATA0;
PORTCbits.RC1=0;// WR1;
sdata<<=1;
}
}
/**-------------------------------------------------------------------------
Name: SendCmd(送命令)
---------------------------------------------------------------------------*/
void SendCmd_1621(uchar command)
{
PORTCbits.RC0=1; //CS0;
SendBit_1621(0x80,4); //写入标志码“100”和9 位command 命令,由于
SendBit_1621(command,8); //没有使有到更改时钟输出等命令,为了编程方便
PORTCbits.RC0=0; //CS1; //直接将command 的最高位写“0”
}
/**-------------------------------------------------------------------------
Name: Write_1621(送数据和命令程序)
---------------------------------------------------------------------------*/
void Write_1621(uchar addr,uchar sdata)
{
addr<<=2;
PORTCbits.RC0=1; //CS0;
SendBit_1621(0xa0,3); //写入标志码“101”
SendBit_1621(addr,6); //写入addr 的高6位
SendBit_1621(sdata,4); //写入data 的8位
PORTCbits.RC0=0; //CS1;
}
/**-------------------------------------------------------------------------
Name: all_off(清除1621显示)
---------------------------------------------------------------------------*/
void HT1621_all_off(void)
{
addr_1621=0;
for(i_1621=0;i_1621<32;i_1621++)
{
Write_1621(addr_1621,0x00);
addr_1621+=1;
}
}
/****************************************************************************
Name: all_on(全部点亮1621)
****************************************************************************/
void HT1621_all_on(void)
{
addr_1621=0;
for(i_1621=0;i_1621<32;i_1621++)
{
Write_1621(addr_1621,0xff);
addr_1621+=1;
}
}
/****************************************************************************
Name: Init_1621(初始化1621)
*****************************************************************************/
void Init_1621(void)
{
// DDRB|=0x1F;
SendCmd_1621(Sys_en);
SendCmd_1621(RCosc);
SendCmd_1621(ComMode);
SendCmd_1621(LCD_on);
}
/****************************************************************************
Name: LCDon(初始化1621)
*****************************************************************************/
void LCDoff(void)
{
SendCmd_1621(LCD_off);
}
/****************************************************************************
Name: LCDon(初始化1621)
*****************************************************************************/
void LCDon(void)
{
SendCmd_1621(LCD_on);
}
这是函数,设置与端口连接
其中1621接受的是时序,但是我现在就是时序发布出去
|