
<reg52.h>
void
delay(int
a)
//延迟程序
{
while(a--)
}
main(){
P1=0x01
/纳梁宏/P1口初始0000
0001
while(1){
while(P1!=0x80){
//当p1口不是
1000
0000时
P1口左移一位,本来起初是0000
0001,500毫
秒后变成
0000
0010,然后0000
0100,直到变成1000
0000
P1=P1<<1
delay(5000)
}
while(P1!=0x01){
//同理
1000
0000
右移渣带
变成0100
0000,因为P1口接led,高电位时洞册点亮
P1=P1>>1
delay(5000)
}
}
}
Java怎么滚唯编写走马灯程序代码:package clock
import java.awt.*
import java.awt.event.*
import javax.swing.*
import java.util.Calendar
import java.util.Date
import java.text.*
public class removingLight extends JFrame {
public removingLight() {
Font font1 = new Font("幼圆", Font.BOLD, 16)
Calendar cal = Calendar.getInstance()
SimpleDateFormat formatter = new SimpleDateFormat(
"EEEE,MMMMdd日,没迟yyyy年 HH:mm:ss")
String mDateTime = formatter.format(cal.getTime())
MovingMessagePanel messagePanel = new MovingMessagePanel(mDateTime)
messagePanel.setFont(font1)
messagePanel.setBackground(Color.BLACK)
messagePanel.setForeground(Color.PINK)
add(messagePanel)
}
public static void main(String[] args) {
removingLight frame = new removingLight()
JLabel label = new JLabel("枯备李开始调试时间:5月5日 结束调试时间:5月6日")
label.setBackground(Color.black)
frame.setTitle("软件1班 XXX 3107006757")
frame.setLocationRelativeTo(null)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setSize(320, 120)
frame.setVisible(true)
frame.add(label, BorderLayout.SOUTH)
}
static class MovingMessagePanel extends JPanel {
private String message = " "
private int xCoordinate = 0
private int yCoordinate = 40
public MovingMessagePanel(String message) {
this.message = message
Timer timer = new Timer(100, new TimerListener())
timer.start()
}
public void paintComponent(Graphics g) {
super.paintComponent(g)
if (xCoordinate >getWidth()) {
xCoordinate = -100
}
xCoordinate += 5
g.drawString(message, xCoordinate, yCoordinate)
}
class TimerListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
repaint()
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)