Sunday, April 15, 2018

Arduino UNO /AVR 328P Serial USART Transmission in Assembly




;
; Serial USART.asm
;
; Created: 4/15/2018 9:24:49 PM
;

.equ    UBRRNX0=103    ; 9600bps
.equ    UBRRNX1=207

// start code
start:
    rcall    USART_Init
    ; write your code here
    ldi        r16,0x24
    rcall USART_Transmit   

end:
    rjmp    end

; end of your code
; this is my part
;----------
USART_Init:
    push r16
    push r17
       
    ldi r16, low(UBRRNX0)            ; Set baud rate to UBRR0
    ldi r17, high(UBRRNX0)
    sts UBRR0H, r17
    sts UBRR0L, r16
       
    ldi r16, (1
<<RXEN0)|(1<<TXEN0)    ; Enable receiver and transmitter
    sts UCSR0B,r16
       
    ldi r16, (1
<<USBS0)|(3<<UCSZ00)    ; Set frame format: 8data, 2stop bit
    sts UCSR0C,r16
    pop r17
    pop r16
    ret

USART_Transmit:
    push r17
    lds r17, UCSR0A                    ; Wait for empty transmit buffer
    sbrs r17, UDRE0
    rjmp USART_Transmit
       
    sts UDR0,r16                    ; Put data (r16) into buffer, sends the data
    pop r17
    ret

Sunday, April 8, 2018

Arduino UNO Blinking with Timer on Assembly


.equ    DELOOP=10
.MACRO  CPL                    ; Macro to complemen pin
    sbi    0x1E,    @1            ; use this register to xor the pin
    in    r17,    0x1E
    in    r16,    @0        
    eor r16,    r17        
    out @0,        r16
.ENDMACRO

.ORG 0x0000                    ; The beginning of everything
    rjmp START                ; the reset vector: jump to "main"

.ORG 0x0020                    ; interrupt vector: timer0 overflow
    rjmp timer0_overflow    ; jump to interrupt handler

.ORG 0x0034                    ; memory address start of "main function"
START:
    ldi r22,    DELOOP                ; initial value for timer looping

    ldi r16,    0xFF         
    out DDRB,    r16            ; set Port B as output

    ldi r16,    0x0000   
    out TCCR0A, r16            ; timer 0 run in normal mode
    ldi r16,    0x0001   
    sts TIMSK0,    r16
    ldi r16,    0b00000101        ; Set r16 with prescaler 1024 value
    out TCCR0B, r16            ; Set the TCCROB to 1024
    SEI                        ; enable global interrupt

LOOP:
    rjmp LOOP            ; jump to loop

timer0_overflow:
    dec        r22
    breq    toggle
    reti

toggle:                    ; the subroutine:
    ldi        r22, DELOOP
    CPL        PortB, 5            ; toggle the LED
    reti





Load programs to an Arduino UNO from Atmel Studio 7

Many tools can be used, but I like mostly Arduino Sketch Uploader



ArduinoSketchUploader
arduino-uno-from-atmel-studio-7
other
other

Saturday, April 7, 2018

Reset MySQL Root Password

-----
Basic step to reset mysqld password just follow these instructions :
  • Stop the mysql demon process
    •    sudo /etc/init.d/mysql stop
  • Start the mysqld demon process using the --skip-grant-tables option
    •    sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
      or
         sudo mysqld_safe --skip-grant-tables &
       
  • start the mysql client process using this command
    •    mysql -u root
  • from the mysql prompt execute this command to be able to change any password
    •    FLUSH PRIVILEGES;
  • Then reset/update your password
    •    SET PASSWORD FOR root@'localhost' = PASSWORD('password');
  • If you have a mysql root account that can connect from everywhere, you should also do:
    •    UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
  • Alternate Method:
    •    USE mysql
         UPDATE user SET Password = PASSWORD('newpwd')
         WHERE Host = 'localhost' AND User = 'root';
  • And if you have a root account that can access from everywhere:
    •    USE mysql
         UPDATE user SET Password = PASSWORD('newpwd')
         WHERE Host = '%' AND User = 'root';
For either method, once have received a message indicating a successful query (one or more rows affected), flush privileges:
   FLUSH PRIVILEGES;

Then stop the mysqld process and relaunch it
   sudo /etc/init.d/mysql stop
   sudo /etc/init.d/mysql start
 

-- Alternative method for different source
 
1. Run bash commands
 

# 1. first, run these bash commands
sudo /etc/init.d/mysql stop # stop mysql service
sudo mysqld_safe --skip-grant-tables & # start mysql without password
# enter -> go
mysql -uroot # connect to mysql

2. Run mysql commands

use mysql; # use mysql table
update user set authentication_string=PASSWORD("") where User='root'; # update password to nothing
update user set plugin="mysql_native_password" where User='root'; # set password resolving to default mechanism for root user

flush privileges;
quit;

3. Run more bash commands

sudo /etc/init.d/mysql stop 
sudo /etc/init.d/mysql start # reset mysql 
mysql -u root -p root # try login to database
 
 

-- If you find following error

2017-02-10T17:05:44.870970Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-02-10T17:05:44.872874Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-02-10T17:05:44.874547Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists. 
 
Do this 
$ mkdir -p /var/run/mysqld
$ chown mysql:mysql /var/run/mysqld

To reset 
Mysqld_safe 
Solving Error 
 

Thursday, April 5, 2018

Setup PHP on Ubuntu

Please check these links

LAMP
LAMP how to

To install PHP 7 on Ubuntu 
sudo apt-get -y update
sudo add-apt-repository ppa:ondrej/php
sudo apt-get -y update
sudo apt-get install -y php7.0 libapache2-mod-php7.0 php7.0 php7.0-common php7.0-gd php7.0-mysql php7.0-mcrypt php7.0-curl php7.0-intl php7.0-xsl php7.0-mbstring php7.0-zip php7.0-bcmath php7.0-iconv php7.0-soap
 

 
PHP install guide

to Upgrade to PHP7
PHP7

 If an "PHP ERROR: Module php7.0 does not exist" occur

PHP ERROR

to install PHPmyAdmin

sudo apt-get install phpmyadmin
phpMyAdmin

Tuesday, April 3, 2018

Adaptive Runge Kutta to Solve ODE

This is a paperwork of my student. You can refer to this.

Download paper