这是c51的
/**************************************************************************
File Name: main.c
Description: WT588D test programme
compiler: Keil C51 9.02a
Author: LJW
Created: 2011/09/02
Modified: NO
Revision: 1.0
MCU: STC10F04
Oscillator Crystal Frequency: 11.0592MHz
***************************************************************************/
/****************************************************/
/* */
/* Included files */
/* */
/****************************************************/
#include "STC8051.H" /* STC8051 definitions */
#include <Delay.h>
/****************************************************/
/* */
/* 1ü½Å¶¨òå */
/* */
/****************************************************/
/////////////////////////////////
sbit key1 = P3^7;
sbit key2 = P3^6;
sbit key3 = P2^4;
sbit key4 = P2^3;
sbit LED_OUT = P2^0;
sbit FLAG_OUT = P2^1;
//1Line_A
sbit P_DATA = P0^0; //¶¨òåêy¾Y′«êä¶Ë¿ú¶Ôó|óïòôD¾Æ¬
03
//3Line_A
sbit P_DATA_3A = P0^0; //¶¨òåêy¾Y′«êä¶Ë¿ú
sbit CS_3A = P0^1; //¶¨òåƬѡDÅoŶ˿ú
sbit CLK_3A = P0^2; //¶¨òåê±Öó¶Ë¿ú
//ò»Ïߣ¬¶tÏߣ¬èyÏßóD1Ø
#define H 1 //¶¨òå1Îa¸ßμçƽ
#define L 0 //¶¨òå0Îaμíμçƽ
//////////////񄠨/////////////////
//bit flag = 1;
bit B_DATA; //′«êäêy¾Yò»Î»
unsigned char SB_DATA = 0; //ò»×Ö½ú1«óÃêy¾Y»o′æÆ÷
unsigned char S_DATA = 0x00;
/******************************************
¼üÅìé¨Ãèoˉêy
*******************************************/
unsigned char key,key_zhi;
unsigned int ADJ_NUM = 6;
unsigned int S_time = 5;
/*--------------------------------------
;Ä£¿éÃû3Æ
ine_1A(void)
;1| Äü:êμÏÖò»Ïßμ¥×Ö½úμíλÔúÇ°′®¿úí¨DÅoˉêy
;èë 2Î:ÎT
;3ö 2Î:0 ·μ»ØÖ÷oˉêy
;-------------------------------------*/
void Line_1A(unsigned char dat)
{
unsigned char i;
//********************************************************
P_DATA = 0;
Delay_1ms(5); //à-μíÖáéù5ms
B_DATA = dat&0X01;
for(i=0;i<8;i++)
{
P_DATA = 1; //à-¸ßêy¾Y′«êäÏߣ¬×¼±¸′«êäêy¾Y
if(B_DATA==0)
{ /*±íê¾Âß¼-μçƽ0*/
Delay_10us(20); // Ñóê±200us
P_DATA = 0;
Delay_10us(20); // Ñóê±600us
Delay_10us(20);
Delay_10us(20);
}
else
{ /*±íê¾Âß¼-μçƽ1*/
Delay_10us(20);
Delay_10us(20);
Delay_10us(20);
P_DATA = 0;
Delay_10us(20);
}
dat = dat>>1;
B_DATA = dat&0X01;
}
P_DATA = 1; //à-¸ßμçƽ
}
/*--------------------------------------
;Ä£¿éÃû3Æ
ine_3A(void)
;1| Äü:êμÏÖèyÏßμ¥×Ö½úμíλÔúÇ°′®¿úí¨DÅoˉêyêêóÃóúWT588D
;èë 2Î:ÎT
;3ö 2Î:0 ·μ»ØÖ÷oˉêy
;-------------------------------------*/
void Line_3A(unsigned char dat)
{
unsigned char i,key_copy = 0X00;
P_DATA = 1;
CLK_3A = H; //à-¸ß
CS_3A= L; //à-μíƬѡDÅoÅ
Delay_1ms(5); //5ms
B_DATA = dat&0X01;
for(i=0;i<8;i++)
{
CLK_3A = L; // à-μí
P_DATA_3A = B_DATA; //′«êäêy¾Yò»Î»
Delay_10us(15); //Ñóê±150us
CLK_3A = H; //à-¸ß
Delay_10us(15); //Ñóê±150us
dat = dat>>1;
B_DATA = dat&0X01;
}
P_DATA_3A = 1; //à-¸ßμçƽ
CS_3A = H;
CLK_3A = H;
}
/*************************************************
Function: Main
Description: Main Function
Input: void
Output: NULL
Return: void
*************************************************/
void main()
{
//P0¿úéèÎa¿a©¼«êä3ö·½ê½
P0M0 = 0xff;
P0M1 = 0xff;
P0 = 0xFF;
//P0¿úéèÎaíÆíìêä3ö·½ê½
P2M0 = 0x01;
P4SW = (1<<6); //P4.6ÎaIO¿ú
P_DATA = 1; //à-¸ßêy¾Y¶Ë¿ú
P_DATA_3A = 1; //à-¸ßμçƽ
CS_3A = H;
CLK_3A = H;
while(1)
{
if(key1 == 0)
{
Delay_1ms(30);
if(key1 == 0)
{
LED_OUT = !LED_OUT;
ADJ_NUM ++;
//Line_1A(ADJ_NUM);
Line_3A(ADJ_NUM);
}
while(key1 == 0);
}
if(key2 == 0)
{
Delay_1ms(30);
if(key2 == 0)
{
LED_OUT = !LED_OUT;
ADJ_NUM --;
//Line_1A(ADJ_NUM);
Line_3A(ADJ_NUM);
}
while(key2 == 0);
}
Delay_10ms(150);
}
}
/*----------------------------------------------------------------------------
* end of file
*---------------------------------------------------------------------------*/
一周热门 更多>