定時器源碼
1. sTC單片機 用定時器定時 來控制步進電機 驅動器L298求 源碼 可調速
/*-----------------------------------------------
名稱:步進電機實驗
編寫:shifang
日期:2013.12
修改:無
內容:本程序用於測試兩個4相步進電機常規驅動 用矩陣鍵盤 調節速度
紅外感測器 測速
1602液晶顯示 1-30速度等級,數字越大,速度越大
------------------------------------------------*/
#include <reg52.h>
#include"LCD1602.h"
#include "jzhjp.h"
sbit cesu1=P3^2;
sbit cesu2=P3^3;
unsigned char code table[11]="0123456789.";// 顯示段碼值0~9
unsigned char code table1[]="A:"; //電機1正轉加減速等級
unsigned char code table2[]="B:"; //電機1反轉加減速等級
uint count=0; //外部中斷0計脈沖定義變數
uchar temp1=0; //定時器1計數定義變數
long int v1; //電機1的速度
void Init_Timer0(void); //定時器中斷初始化函數
/*------------------------------------------------
主函數
------------------------------------------------*/
void main()
{
unsigned char num1,num2;
Init_Timer0(); //定辯肆時器中斷初始伍灶罩化
LCD_init(); //LCD1602初始化
write_com(0x80); //顯示A:
for(num1=0;num1<2;num1++)
{
write_data(table1[num1]);
delay(5);
}
write_com(0x80+0x40); //顯示B:
for(num2=0;num2<2;num2++)
{
write_data(table2[num2]);
delay(5);
}
Coil_OFF //初始化全部斷電
while(1)
{
write_com(0x82); //顯示電機1正轉加速值
write_data(table[Speed/10]);
write_data(table[Speed%10]);
write_com(0x80+0x42); //顯示電機1反轉加速值
write_data(table[Speed1/10]);
write_data(table[Speed1%10]);
write_com(0x80+11); //顯示電機1速度值
write_data(table[v1/100]);
write_data(table[v1%100/10]);
write_data(table[10]);
write_data(table[v1%10]);
keyscan(); //矩陣鍵盤腔鬧掃描
}
}
/*------------------------------------------------
定時器初始化子程序
------------------------------------------------*/
void Init_Timer0(void)
{
TMOD |= 0x11; //使用模式1,16位定時器,使用"|"符號可以在使用多個定時器時不受影響
//TH0=0x00; //給定初值
//TL0=0x00;
TH1=(65536-100000)/256; //給定初值50ms
TL1=(65536-100000)%256;
ET1=1; //定時器1中斷打開
PT0=1; //優先順序打開
EA=1; //總中斷打開
IT0=1; //1表示邊沿觸發
IT1=1; //1表示邊沿觸發
}
/*------------------------------------------------
定時器0中斷子程序
------------------------------------------------*/
void Timer0_isr(void) interrupt 1
{
static unsigned char times,i;
static unsigned char times1,j;
TH0=(65536-500)/256; //重新賦值 0.5ms
TL0=(65536-500)%256;
if(flag==1) //電機1正轉
{
if(times==(50-Speed))
{
times=0;
switch(i)
{
case 0:Coil_a1;i++;break;
case 1:Coil_ab1;i++;break;
case 2:Coil_b1;i++;break;
case 3:Coil_bc1;i++;break;
case 4:Coil_c1;i++;break;
case 5:Coil_cd1;i++;break;
case 6:Coil_d1;i++;break;
case 7:Coil_da1;i++;break;
case 8:i=0;break;
default:break;
}
}
else
times++;
}
if(flag1==1) //電機1反轉
{
if(times1==(50-Speed1))
{
times1=0;
switch(j)
{
case 0:Coil_da1;j++;break;
case 1:Coil_d1;j++;break;
case 2:Coil_cd1;j++;break;
case 3:Coil_c1;j++;break;
case 4:Coil_bc1;j++;break;
case 5:Coil_b1;j++;break;
case 6:Coil_ab1;j++;break;
case 7:Coil_a1;j++;break;
case 8:j=0;break;
default:break;
}
}
else
times1++;
}
}
/*------------------------------------------------
定時器0中斷子程序
------------------------------------------------*/
void time1() interrupt 3
{
TH1=(65536-10000)/256; //重裝初值10ms
TL1=(65536-10000)%256;
temp1++;
if(temp1==100) //1s采樣1次
{
temp1=0;
v1=count*3; //速度單位:轉/min
count=0; //v=(count/20/1)*60=count*3;
}
}
/*--------------------------------------------------
外部中斷0子程序
---------------------------------------------------*/
void ISR_INT0(void) interrupt 0
{
if(cesu1==0) //電機1碼盤脈沖計數
{
delay(5);
if(cesu1==0)
{
count++;
}
while(!cesu1);
}
}
顯示部分你自己弄一下
2. 求每日定時在伺服器的FTP上取數據文件的源碼(java)
這個是可以向伺服器端發送文字的程序,就是在客戶端發送一句hello在伺服器也可以接受到hello,這個程序可以修改一下就可以了。具體修改方法是增加一個定時器,然後把字元流改成位元組流,現在有點忙,你先研究啊,近兩天幫你寫寫看。
伺服器端:
import java.net.*;
import java.io.*;
public class DateServer {
public static void main(String[] args) {
ServerSocket server=null;
try{
server=new ServerSocket(6666);
System.out.println(
"Server start on port 6666...");
while(true){
Socket socket=server.accept();
new SocketHandler(socket).start();
/*
PrintWriter out=new PrintWriter(
new OutputStreamWriter(
socket.getOutputStream()
)
);
out.println(new java.util.Date().toLocaleString());
out.close();
*/
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(server!=null) {
try{
server.close();
}catch(Exception ex){}
}
}
}
}
class SocketHandler extends Thread {
private Socket socket;
public SocketHandler(Socket socket) {
this.socket=socket;
}
public void run() {
try{
PrintWriter out=new PrintWriter(
new OutputStreamWriter(
socket.getOutputStream()
)
);
out.println(
new java.util.Date().
toLocaleString());
out.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
客戶端:
package com.briup;
import java.io.*;
import java.net.*;
public class FtpClient {
public static void main(String[] args) {
if(args.length==0) {
System.out.println("Usage:java FtpClient file_path");
System.exit(0);
}
File file=new File(args[0]);
if(!file.exists()||!file.canRead()) {
System.out.println(args[0]+" doesn't exist or can not read.");
System.exit(0);
}
Socket socket=null;
try{
socket=new Socket(args[1],Integer.parseInt(args[2]));
BufferedInputStream in=new BufferedInputStream(
new FileInputStream(file)
);
BufferedOutputStream out=new BufferedOutputStream(
socket.getOutputStream()
);
byte[] buffer=new byte[1024*8];
int i=-1;
while((i=in.read(buffer))!=-1) {
out.write(buffer,0,i);
}
System.out.println(socket.getInetAddress().getHostAddress()+" send file over.");
in.close();
out.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(socket!=null) {
try{
socket.close();
}catch(Exception ex){}
}
}
}
}
3. C語言 電子時鍾源代碼程序 帶圖 謝謝 最好有注釋
#include <stdio.h>
#include <time.h>
#include"stdlib.h"
#include "windows.h"
void main ()
{
while(1)
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( " 07The current date/time is: %s", asctime (timeinfo) );
Sleep(1000);
system("cls");
}
}